Simple question on adding message box to list all the item that is not same

  • Thread starter EMILYTAN via AccessMonster.com
  • Start date
E

EMILYTAN via AccessMonster.com

I want to add a message box that will list the item that is not the same...

Below is part of the code my code :-
Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
End If

This code can work when the part number is the same...But when it is
different, i want it to display into a message box and list all that is not
same at the end of the code...
Can someone help...
I actually tried to put in an array to store it but it didnt seems to work..
Glad if some one willing to help...(",)
 
S

Steve

Look up NoMatch in the Help file then add a If/Then comparison using NoMatch
to your code and open a messagebox when there is no match.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
 
E

EMILYTAN via AccessMonster.com

Can't get the content of NoMatch...
Look up NoMatch in the Help file then add a If/Then comparison using NoMatch
to your code and open a messagebox when there is no match.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
I want to add a message box that will list the item that is not the same...
[quoted text clipped - 21 lines]
work..
Glad if some one willing to help...(",)
 
E

EMILYTAN via AccessMonster.com

I am sorry if I am wrong...but is this the one....
But it need to have the function...
This is all under a command click...
Besides, this will prompt the user quite multiple times with msg box. I hope
to prompt the user with only a message box...
Need guidance...
Thanks
Below is the code:-
If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
End If
If myrecset1.NoMatch Then
strMessage = _
"Not found! Returning to current record." & _
vbCr & vbCr & "NoMatch = " & myrecset1!PartNumber.NoMatch
MsgBox strMessage

End If
Look up NoMatch in the Help file then add a If/Then comparison using NoMatch
to your code and open a messagebox when there is no match.

PC Datasheet
Providing Customers A Resource For Help With Access, Excel And Word
Applications
(e-mail address removed)
I want to add a message box that will list the item that is not the same...
[quoted text clipped - 21 lines]
work..
Glad if some one willing to help...(",)
 
A

AccessVandal via AccessMonster.com

Hi Emily.

You need to use the MoveNext, here is a sample

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

‘if myrecset1 is not EOF, you need to movefirst in “myrecset†to loop through
to match ‘“myrecset1â€.
'Since "myrecset" is EOF and "myrecset1" is not EOF, you need to use
MoveFirst for "myrecset".

If myrecset.EOF Then
myrecset.MoveFirst
End if

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
myrecset.MoveNext ‘use the movenext record in this recordset
myrecset1.MoveNext ‘and this one also
Else
myrecset.MoveNext ‘if no match movenext for this recordset
End If
 
E

EMILYTAN via AccessMonster.com

Thanks for your sample..but I need to know the way of showing a message box
with a list of part number that is not the same...really need guidance for
that...
Hi Emily.

You need to use the MoveNext, here is a sample

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

‘if myrecset1 is not EOF, you need to movefirst in “myrecset†to loop through
to match ‘“myrecset1â€.
'Since "myrecset" is EOF and "myrecset1" is not EOF, you need to use
MoveFirst for "myrecset".

If myrecset.EOF Then
myrecset.MoveFirst
End if

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
myrecset.MoveNext ‘use the movenext record in this recordset
myrecset1.MoveNext ‘and this one also
Else
myrecset.MoveNext ‘if no match movenext for this recordset
End If
I want to add a message box that will list the item that is not the same...
[quoted text clipped - 17 lines]
I actually tried to put in an array to store it but it didnt seems to work..
Glad if some one willing to help...(",)
 
A

AccessVandal via AccessMonster.com

Hi Emily,

Just include the message box after "Else". like....

myrecset.MoveNext ‘use the movenext record in this recordset
myrecset1.MoveNext ‘and this one also
Else
MsgBox "No matching Record",vbInformation,"No Match" 'just include this
line here
myrecset.MoveNext ‘if no match movenext for this recordset
End If
 
A

AccessVandal via AccessMonster.com

Hi Emily,

Refer to edit message box.. forgot to include the "list part number"

MsgBox "No matching part number " & myrecset!PartNumber ,vbInformation,"No
Match"

Note: if there are hundreds or thousands no matching records, would the users
will get sick and complaint?
 
E

EMILYTAN via AccessMonster.com

Yaya...you are right..Initially I plan to do that...
However, after thinking of that, I need it to list in a message box and
appear a list after the update is being done...
That is the difficult part I encounter...
 
A

AccessVandal via AccessMonster.com

Hi Emily,

Then, don’t use the message box in that “If Than Else†statement.

What you need is a string concatenation. Something like ….

Dim strmyrecset As String ‘ somewhere above

Else
myrecset.MoveNext ‘if no match movenext for this recordset
strmyrecset = strmyrecset & “,†& myrecset!PartNumber
End If

‘somewhere below here after the “IF Than Elseâ€

‘ if not null or blank, if there are unmatch records
If Not IsNull(strmyrecset) & “ = “ Then
MsgBox “What Ever message here†& strmyrecset, vbInformation,â€What ever title
hereâ€
Else
MsgBox “All Records Matchedâ€,vbInformation,â€What ever title hereâ€
End If

Than again, why use message box if there are thousands that will fill up the
desktop screen?

I would use a query or a form in datasheet view all records that do not match.


After the “.Execute If Else Then†statement, I would run a command to open a
query or a form in datasheet view with a record source ….

The query would be something like…

SELECT * FROM Table1, Table2, Table3 INNER JOINT Table1.Col1 = Table2.Col1…..

Hope to get you started somewhere.
 
A

AccessVandal via AccessMonster.com

Hi Emily,

Then, don’t use the message box in that “If Than Else†statement.

What you need is a string concatenation. Something like ….

Dim strmyrecset As String ‘ somewhere above

Else
myrecset.MoveNext ‘if no match movenext for this recordset
strmyrecset = strmyrecset & “,†& myrecset!PartNumber
End If

‘somewhere below here after the “IF Than Elseâ€

‘ if not null or blank, if there are unmatch records
If Not IsNull(strmyrecset) & “ = “ Then
MsgBox “What Ever message here†& strmyrecset, vbInformation,â€What ever title
hereâ€
Else
MsgBox “All Records Matchedâ€,vbInformation,â€What ever title hereâ€
End If

Than again, why use message box if there are thousands that will fill up the
desktop screen?

I would use a query or a form in datasheet view all records that do not match.


After the “.Execute If Else Then†statement, I would run a command to open a
query or a form in datasheet view with a record source ….

The query would be something like…

SELECT * FROM Table1, Table2, Table3 INNER JOINT Table1.Col1 = Table2.Col1…..

Hope to get you started somewhere.
 
E

EMILYTAN via AccessMonster.com

Before showing you the code, let me clarify something.
Example,
Old New
001 001
002 002
003

So, for the part number that is not equal, will only show 003 in the message
box.

Codes:-


If myrecset1.BOF And myrecset1.EOF Then
MsgBox "There are no part numbers tied to this old job #:" & Me.
txtJobNumberOld
'strmyrecset = strmyrecset & "," & myrecset!PartNumber
myrecset1.Close
Exit Sub
Else
'loop through the part #'s of the old job #

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQTY
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
Else
strmyrecset = strmyrecset & "," & myrecset1!PartNumber
End If
myrecset1.MoveNext
Loop
myrecset1.Close
End If
myrecset.MoveNext
Loop
myrecset.Close
If Not IsNull(strmyrecset) Then
MsgBox "What Ever message here" & strmyrecset, vbInformation, "What ever
title"


Sorry to say the previous code will actually make my access not responding...
haha...
This code :- strmyrecset = strmyrecset & "," & myrecset1!PartNumber
will actually show all the partnumber that is in old.
Any to replace that?
Thanks for your sincere help...
 
E

EMILYTAN via AccessMonster.com

Hey, I have made some changes..
I have change this line "strmyrecset = strmyrecset & "," & myrecset1!
PartNumber" to strmyrecset=myrecset!PartNumber and it can give me result that
the PartNumber is not the same..

However, it can only give me 1 part number and not the whole list...
Any idea of storing it in whole list...?
Before showing you the code, let me clarify something.
Example,
Old New
001 001
002 002
003

So, for the part number that is not equal, will only show 003 in the message
box.

Codes:-

If myrecset1.BOF And myrecset1.EOF Then
MsgBox "There are no part numbers tied to this old job #:" & Me.
txtJobNumberOld
'strmyrecset = strmyrecset & "," & myrecset!PartNumber
myrecset1.Close
Exit Sub
Else
'loop through the part #'s of the old job #

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQTY
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
Else
strmyrecset = strmyrecset & "," & myrecset1!PartNumber
End If
myrecset1.MoveNext
Loop
myrecset1.Close
End If
myrecset.MoveNext
Loop
myrecset.Close
If Not IsNull(strmyrecset) Then
MsgBox "What Ever message here" & strmyrecset, vbInformation, "What ever
title"

Sorry to say the previous code will actually make my access not responding...
haha...
This code :- strmyrecset = strmyrecset & "," & myrecset1!PartNumber
will actually show all the partnumber that is in old.
Any to replace that?
Thanks for your sincere help...
Hi Emily,
[quoted text clipped - 38 lines]
 
A

AccessVandal via AccessMonster.com

Hi Emily,

There are question that I need to know.

1. “myrecset†is Old ?
2. “myrecset1 is New?
3. why don’t you just use Update SQL syntax like I have suggested about the
datasheet view?(table joins)
4. What’s the new code? “If myrecset1.BOF And myrecset1.EOF Thenâ€. It does
nothing for you. It’s not what I gave you.
5. Do you understand what is “EOF†and “BOF�
6. Did you “Dim†the variable “strmyrecset�
7. You miss the “MoveNext†again?


Let’s recap on the prevoius code

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

‘if myrecset1 is not EOF, you need to movefirst in “myrecset†to loop through
to match ‘“myrecset1â€.
'Since "myrecset" is EOF and "myrecset1" is not EOF, you need to use
MoveFirst for "myrecset".

If myrecset.EOF = True Then ‘I have put “True†to avoid confusion
myrecset.MoveFirst ‘move to first record if “myrecset1†is not EOF.
End if
’I put this code above here because sometimes the sorting order is “not in
orderâ€
‘the purpose is to match the partnumber and this code must be here.
‘Else you must ensure that the tables are in proper sorting order.

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
myrecset.MoveNext ‘use the movenext record in this recordset
myrecset1.MoveNext ‘and this one also
’This is the part of “MoveNext you missing again
Else
myrecset.MoveNext ‘if no match movenext for this recordset
End If

‘ if not null or blank, if there are unmatch records, show message box
If Not IsNull(strmyrecset) & “ = “ Then
MsgBox “What Ever message here†& strmyrecset, vbInformation,â€What ever title
hereâ€
Else
‘if you still want to show message
MsgBox “All Records Matchedâ€,vbInformation,â€What ever title hereâ€
End If
‘Remember to close all recordset

If “Old†and “New†is reversed.. than just change the recordsets.

If myrecset1.EOF = True Then
myrecset1.MoveFirst
End if

And in this part
CurrentDb.Execute mySQL2, dbFailOnError
myrecset.MoveNext
myrecset1.MoveNext
’This is the part of “MoveNext you missing again
Else
’just change to myrecset1 here
myrecset1.MoveNext
End If
 
A

AccessVandal via AccessMonster.com

Hi Emily,

Forgot the include the change to recordset "myrecset1".

Change the "Do Until myrecset1.EOF" to "Do Unit myrecset.EOF"

you need to cycle the correct recordsets.
 
A

AccessVandal via AccessMonster.com

Hi Emily,

forgot about the "Else" string part .

Else
myrecset1.MoveNext ‘if no match movenext for this recordset
strmyrecset = strmyrecset & “,†& myrecset1!PartNumber 'if this is Old
part?
End If

Note: If the recordsets was reversed, change it to from "myrecset" to
"myrecset1".
 
E

EMILYTAN via AccessMonster.com

Well, this is what I have done...

Do Until myrecset1.EOF

'open a record set to get part number and kitted QTY for old Job
number
mySQL1 = "SELECT WIPRawDetails.PartNumber, W_KittedQTY FROM
WIPRawDetails WHERE WIPRawDetails.JobNumber='" & Me.txtJobNumberOld & "'"

myrecset.Open mySQL1

'check to make sure data (part #'s) are present for the old job #
If myrecset.BOF And myrecset.EOF Then
MsgBox "There are no part numbers tied to this old job #:" & Me.
txtJobNumberOld
'strmyrecset = strmyrecset & "," & myrecset!PartNumber
myrecset.Close
Exit Sub
Else
'loop through the part #'s of the old job #

Do Until myrecset.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

If myrecset1!PartNumber = myrecset!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset1!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
myrecset1.MoveNext
myrecset.MoveNext
Else
myrecset.MoveNext
strmyrecset = strmyrecset & "," & myrecset!PartNumber
End If
If Not IsNull(strmyrecset) Then
MsgBox "What Ever message here" & strmyrecset1, vbInformation, "What ever"""

Else

MsgBox "Update has been completed"


If myrecset1.EOF = True Then
myrecset.MoveFirst
End If
Loop
myrecset.Close
End If
myrecset1.MoveNext
Loop
myrecset1.Close

Set myrecset1 = Nothing
Set myrecset = Nothing
End If
End If

Well, I understand what is meant by .EOF and .BOF...
I know it is kind off troublesome to get your help to go through this code,
but I really hope to learn something from mistakes...Thanks
 
A

AccessVandal via AccessMonster.com

Hi Emily,

Have you tested the code by inserting breakpoints? You need to debug the
codes to see that it works for you. Please new comments in the codes
carefully and compare with mine from the last post.
EMILYTAN wrote:
‘--------------------------------this is what you posted----------------------
-------------------
Well, this is what I have done...

Do Until myrecset1.EOF

'open a record set to get part number and kitted QTY for old Job
number
mySQL1 = "SELECT WIPRawDetails.PartNumber, W_KittedQTY FROM
WIPRawDetails WHERE WIPRawDetails.JobNumber='" & Me.txtJobNumberOld & "'"

myrecset.Open mySQL1 ‘I presume this was working
’---------------------------this part of the code may not work----------------
-----------
'check to make sure data (part #'s) are present for the old job #
’ If myrecset.BOF And myrecset.EOF Then
’ MsgBox "There are no part numbers tied to this old job #:" & Me.
’txtJobNumberOld
’ 'strmyrecset = strmyrecset & "," & myrecset!PartNumber
’ myrecset.Close
’ Exit Sub
‘I have commented it out
‘----------------it will very like go to Else or may not----------------------
--------------
‘when recordset “myrecset†is open and if there are records,
‘BOF is “True†and EOF is “Falseâ€
‘if there are no records, you need to change it to………
‘â€If myrecset.BOF = False And myrecset.EOF = True Thenâ€
‘use don’t need to use BOF, just use EOF.
‘if you wish to check “is there any records?†and exit, just use..

If myrecset.EOF = True Then
MsgBox "There are no part numbers tied to this old job #:" & Me.
txtJobNumberOld
‘you need to close your recordset here? What about “myrecset1�
‘is it use somewhere?
myrecset.Close
Exit Sub
End If

‘This code above here is not for checking matching records, it’s your query
“mySQL1â€
’-----------------------------------------------------------------------------
-----------------------
‘--------------commented out-----------------------------
‘ Else
‘----------------------------------------------------------------
'loop through the part #'s of the old job #

Do Until myrecset.EOF

’----part of the code is missing here-----------------------------------------
-
‘this part of the code is to recycle one of the recordset to match the
‘the “Do Until myrecset.EOF is “Trueâ€. Because it is still “Falseâ€, you
‘need to recycle the recordset “myrecset1†to match “myrecset†until
‘â€myrecset.EOF = True†where it will exit the Loop. (use this only if the
table
‘sorting order is not set correctly.)

If myrecset1.EOF = True And myrecset.EOF = False Then
myrecset1.MoveFirst
End If

‘I have edited it to recordset “myrecset1†as you want cycle back to first
record
‘As for recordset “myrecsetâ€, refer to the “Do Until“ “Else†part
‘
‘----this code is important! If your tables are not in proper sorting order---
-
‘like I said, if the recordsets are reversed, change them
‘if “myrecset1†is the one you wish to recycle to the top the record.
‘You do not need to recycle the recordset in the “Do Untilâ€
‘if it is recordset “myrecset†change it accordingly.
‘Please refer to the previous post comments
‘-----------------------------------------------------------------------------
-----------

'if part numbers of the two jobs are the same, perform the
’update, if not move on to next part number in old job
If myrecset1!PartNumber = myrecset!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset1!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError

’----It appears that you don’t understand this part-----------
‘If both recordsets “myrecset†and “myrecset1†matches, move both
‘record pointer to next record.

myrecset1.MoveNext
myrecset.MoveNext
Else

‘-----------------------------------------------------------------------------
-------
’if recordset “myrecset†does not match “myrecset1â€, move next
‘record for “myrecset1†only but not “myrecsetâ€. Why don’t move
‘â€myrecset1â€? you might ask. Refer to “Do Until†above.
‘Here lies one problem, what if “myrecset†doe not match and
‘will loop continuously?
‘This where you must make sure that “myrecset†and “myrecset1â€
‘records exist in both queries. Only one recordset, in this case
‘recordser “myrecset1†has one or more unmatch record. Only
‘this recordset “myrecset1†must be the one you want to
‘recycle to MoveFirst to the top of the record. Recordset
‘â€myrecset†will end the loop once the .EOF is True.
‘So the chances of a continuous looping is prevented.
‘
‘if you MoveNext “myrecsetâ€, this unmatch record will not be
‘updated. Unless that’s what you intend to do if both recordsets
‘have unmatching records, but this will not work well.

myrecset1.MoveNext
strmyrecset = strmyrecset & "," & myrecset1!PartNumber
End If
’-----------------------------------------------------------------------------
------

‘---The Loop should be here-------------------
Loop ‘Loop until myrecset.EOF = True
‘------------------------------------------------------

‘----Display message box here---------------------------------
‘show message box if there are unmatching records

If Not IsNull(strmyrecset) & “ = “ Then ‘not null or is blank
MsgBox "What Ever message here " & strmyrecset1, vbInformation, "What ever
Title"

Else

MsgBox "Update has been completed"
’-------------------------------------------------------------------------
’this lines of code should be just after the “Do Until†line
‘please read last post
’ If myrecset1.EOF = True Then
’ myrecset.MoveFirst
’ End If
‘please refer to top at “Do Untilâ€
‘-------------------------------------------------------------------------
‘----you sure the loop is here?---------------------
‘Loop
’-----------------------------------------------------------------------------
-
‘-----------------------------------------------------------------------------
-
’Do not to close the recordset here, do it after the last End If
‘ myrecset.Close
End If
‘-----------------------------------------------------------------------------
---

‘----this where the Message Box code ends-----------------------

‘------------I have comment this out-------------------
’ myrecset1.MoveNext
’ Loop
’--------------------------------------------------

‘-------Close Recordset--------------------
myrecset.Close
myrecset1.Close

Set myrecset1 = Nothing
Set myrecset = Nothing
‘-----------------------------------------------

‘----comment out--------
’End If
’End If
’-----------------------------

Well, I understand what is meant by .EOF and .BOF...
I know it is kind off troublesome to get your help to go through this code,
but I really hope to learn something from mistakes...Thanks
'-------------------end--------------------------------------

Hope it will get you moving.
 
E

EMILYTAN via AccessMonster.com

Well, it turn out that I am lost while tracing the If..Then...Else...and with
so many move here and there...haha....perhaps, I should show you all the
entire code because I ahve additional codes hide up there...
Well, sorry to make you mad...because first time doing this recordset of
moving here and there..haha
I can't find ways to insert breakpoints....
The codes here runs correctly and accurately...However, problem is that I
didnt include message box to show the user the number that exists in OldJob
only just like what I say previously...



Private Sub cmdInsertItem_Click()
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myrecset As New ADODB.Recordset
Dim myrecset1 As New ADODB.Recordset
myrecset.ActiveConnection = cnn1
myrecset1.ActiveConnection = cnn1
Dim mySQL As String
Dim mySQL1 As String
Dim mySQL2 As String

'Check to make sure the Job Number fields are not blank, if so prompt for
input

If IsNull(Me.txtJobNumberNew) Then
MsgBox "The New job # field cannot be left blank, please enter the new job
number"
Me.txtJobNumberNew.SetFocus
Exit Sub
End If

If IsNull(Me.txtJobNumberOld) Then
MsgBox "The Old job # field cannot be left blank, please enter the old job
number"
Me.txtJobNumberOld.SetFocus
Exit Sub
End If

'open a recordset to hold New Job # data
mySQL = "SELECT WIPRawDetails.PartNumber FROM WIPRawDetails WHERE
WIPRawDetails.JobNumber='" & Me.txtJobNumberNew & "'"
myrecset.Open mySQL

'Check to make sure data (part #'s) are present for New Job #

If myrecset.BOF And myrecset.EOF Then
MsgBox "There are no part numbers tied to this job #:" & Me.txtJobNumberNew
myrecset.Close
Exit Sub
Else

' loop through the part numbers of the New job #

Do Until myrecset.EOF

'open a record set to get part number and kitted QTY for old Job
number
mySQL1 = "SELECT WIPRawDetails.PartNumber, W_KittedQTY FROM
WIPRawDetails WHERE WIPRawDetails.JobNumber='" & Me.txtJobNumberOld & "'"

myrecset1.Open mySQL1

'check to make sure data (part #'s) are present for the old job #
If myrecset1.BOF And myrecset1.EOF Then
MsgBox "There are no part numbers tied to this old job #:" & Me.
txtJobNumberOld
myrecset1.Close
Exit Sub
Else
'loop through the part #'s of the old job #

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
End If
myrecset1.MoveNext
Loop
myrecset1.Close
End If
myrecset.MoveNext
Loop
myrecset.Close
MsgBox "Update has been completed"
End If
Set myrecset = Nothing
Set myrecset1 = Nothing



End Sub

I am lost especially at the end where the loop there....
 
A

AccessVandal via AccessMonster.com

Hi Emily,

In the VB Editor, there is something look like a verticle colored bar, click
on the left of the first line of “IF†statement, you should see a circle/dot
and a
highlighted (Reddish Brown colored) over the “IF†.

Please see and read my comments in your code.

Private Sub cmdInsertItem_Click()
Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim myrecset As New ADODB.Recordset
Dim myrecset1 As New ADODB.Recordset
myrecset.ActiveConnection = cnn1
myrecset1.ActiveConnection = cnn1
Dim mySQL As String
Dim mySQL1 As String
Dim mySQL2 As String

'Check to make sure the Job Number fields are not blank, if so prompt for
input

If IsNull(Me.txtJobNumberNew) Then
MsgBox "The New job # field cannot be left blank, please enter the new job
number"
Me.txtJobNumberNew.SetFocus
Exit Sub
End If

If IsNull(Me.txtJobNumberOld) Then
MsgBox "The Old job # field cannot be left blank, please enter the old job
number"
Me.txtJobNumberOld.SetFocus
Exit Sub
End If

'open a recordset to hold New Job # data
mySQL = "SELECT WIPRawDetails.PartNumber FROM WIPRawDetails WHERE
WIPRawDetails.JobNumber='" & Me.txtJobNumberNew & "'"
myrecset.Open mySQL

'Check to make sure data (part #'s) are present for New Job #

‘-----------------------------------------------------------------------------
---
‘I shall not commend on the BOF and EOF anymore.
’-----------------------------------------------------------------------------
---

If myrecset.BOF And myrecset.EOF Then
MsgBox "There are no part numbers tied to this job #:" & Me.txtJobNumberNew
myrecset.Close
Exit Sub
Else

’-----------------------------------------------------------------------------
-------------------
‘I would recommend that you open both recordsets first here before
‘you use the Do loop.
‘-----------------------------------------------------------------------------
-------------------

'open a record set to get part number and kitted QTY for old Job number

mySQL1 = "SELECT WIPRawDetails.PartNumber, W_KittedQTY FROM
WIPRawDetails WHERE WIPRawDetails.JobNumber='" & Me.txtJobNumberOld & "'"

myrecset1.Open mySQL1

'check to make sure data (part #'s) are present for the old job #
If myrecset1.BOF And myrecset1.EOF Then
MsgBox "There are no part numbers tied to this old job #:" & Me.
txtJobNumberOld
myrecset1.Close
‘-----------------------------------------------------------------------
‘if there are records in “myrecsetâ€, do you want to leave
‘it open? Since there are no records in “myrecset1â€
‘Close “myrecset†and exit procedure
myrecset.Close
‘-----------------------------------------------------------------------
Exit Sub
End If
End If
‘Two “end if†here to exit code. Don’t need Else because
‘there are records in both recordsets. It will proceed
‘to the “Do Until†loop
‘-----------------------------------------------------------------------

' loop through the part numbers of the New job #

’-----------------------------------------------------------------------------
---------------
‘I don’t recommend a Do Loop inside another Do Loop. But if you
‘want to, you can try it out on your own.
‘I will not edit the codes below, will only give comments to help along
‘the way.

‘In your inner Do Loop, it appears that you want to want to MoveNext
‘for “myrecset1â€, leaving “myreset†with the same record to match.
‘Once the record are match and updated, “myrecset1.EOF = Trueâ€
‘the inner Do Loop completes and close “myrecset1â€. Than the
‘outer Do loop continues to MoveNext for “myrecset†but will
‘stop executing at the inner loop “Do Until myrecset1.EOFâ€
‘because you have closed “myrecset1â€. Even if you have not
‘closed “myrecset1â€, “myrecset1.EOF†is “True†and will
‘continue to exit the inner Do Loop and once the outer Do Loop
‘completes, the code exit.

Do Until myrecset.EOF

‘-----------commented out-----------
’ Else
’-------------------------------------------
'loop through the part #'s of the old job #

Do Until myrecset1.EOF
'if part numbers of the two jobs are the same, perform the
update, if not move on to next part number in old job

If myrecset!PartNumber = myrecset1!PartNumber Then
mySQL2 = "Update WIPRawDetails set W_KittedQty =" & myrecset1!
W_KittedQty
mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset!PartNumber & "'"
CurrentDb.Execute mySQL2, dbFailOnError
End If
myrecset1.MoveNext
Loop
myrecset1.Close
End If
myrecset.MoveNext
Loop
myrecset.Close
MsgBox "Update has been completed"
End If
Set myrecset = Nothing
Set myrecset1 = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top