Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / June 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
EMILYTAN - 13 Jun 2007 06:12 GMT
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...(",)
Steve - 13 Jun 2007 06:40 GMT
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
resource@pcdatasheet.com

>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...(",)
EMILYTAN - 13 Jun 2007 06:57 GMT
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.
[quoted text clipped - 9 lines]
>> work..
>> Glad if some one willing to help...(",)
EMILYTAN - 13 Jun 2007 08:32 GMT
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.
[quoted text clipped - 9 lines]
>> work..
>> Glad if some one willing to help...(",)
AccessVandal - 13 Jun 2007 10:56 GMT
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...(",)
EMILYTAN - 18 Jun 2007 01:10 GMT
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.
>
[quoted text clipped - 30 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...(",)
AccessVandal - 18 Jun 2007 01:37 GMT
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

>EMILYTAN wrote:
>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...
AccessVandal - 18 Jun 2007 01:45 GMT
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?

>EMILYTAN wrote:
>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...
EMILYTAN - 18 Jun 2007 04:03 GMT
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...

>Hi Emily,
>
[quoted text clipped - 10 lines]
>>with a list of part number that is not the same...really need guidance for
>>that...
AccessVandal - 18 Jun 2007 05:17 GMT
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.

>EMILYTAN wrote:
>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...
AccessVandal - 18 Jun 2007 05:17 GMT
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.

>EMILYTAN wrote:
>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...
EMILYTAN - 18 Jun 2007 08:07 GMT
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]
>>appear a list after the update is being done...
>>That is the difficult part I encounter...
EMILYTAN - 18 Jun 2007 09:21 GMT
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,
[quoted text clipped - 53 lines]
>>>appear a list after the update is being done...
>>>That is the difficult part I encounter...
AccessVandal - 18 Jun 2007 09:23 GMT
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

>EMILYTAN wrote:
>Before showing you the code, let me clarify something.
[quoted text clipped - 48 lines]
>Any to replace that?
>Thanks for your sincere help...
AccessVandal - 18 Jun 2007 09:28 GMT
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.

>EMILYTAN wrote:
>Before showing you the code, let me clarify something.
>Example,
AccessVandal - 18 Jun 2007 09:40 GMT
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".
EMILYTAN - 19 Jun 2007 03:04 GMT
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

>Hi Emily,
>
[quoted text clipped - 8 lines]
>Note: If the recordsets was reversed, change it to from "myrecset" to
>"myrecset1".
AccessVandal - 19 Jun 2007 09:13 GMT
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.

Signature

Please Rate the posting if helps you

EMILYTAN - 20 Jun 2007 02:47 GMT
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....

>Hi Emily,
>
[quoted text clipped - 183 lines]
>
>Hope it will get you moving.
AccessVandal - 20 Jun 2007 05:34 GMT
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

>EMILYTAN wrote:

Signature

Please Rate the posting if helps you

EMILYTAN - 20 Jun 2007 07:47 GMT
Hi,

I have a few questions:-

1. Why can't we directly add
if partnumber same Then
'update
else
just store the partnumber?

2. Can we change the outer loop to myrecset rather than myrecset1 and inner
loop to myrecset1 rather than myrecset?
>Hi Emily,
>
[quoted text clipped - 137 lines]
>
>>EMILYTAN wrote:
AccessVandal - 20 Jun 2007 11:17 GMT
Hi Emily,

>I have a few questions:-

>1. Why can't we directly add
>if partnumber same Then
>'update
>else
>just store the partnumber?

What do you mean by add directly or directly add?
Do you want to skip the “Do Loop”? If that’s what you mean. The answer is Yes,
but it’s only the first record gets update. Refer to the “MoveNext” and
“MoveFirst” method of moving pointer in recordsets.
Without the Do Loop and MoveNext, the first record will only be the one doing
the matching.
However, you’ll still need to check the recordsets EOF else your code will
stop executing with an error.

>2. Can we change the outer loop to myrecset rather than myrecset1 and inner
>loop to myrecset1 rather than myrecset?

Yes, it depends on what records you were trying to match.

>EMILYTAN wrote:

Signature

Please Rate the posting if helps you

EMILYTAN - 20 Jun 2007 09:42 GMT
Hey,
I have a bright new idea, but not sure whether it will work, so need your
help ...
The new idea is the 1 written with "suggestion"

Brief idea of the suggestion :-

I am using myrecset to be outer loop and myrecset1 to be the inner loop.
Again, note that myrecset is the old job while myrecset1 is the new job...

My idea is, if both of the part number is the same do whatever update, then
just go out to the outer loop to start with the next partnumber of old job.
If both of the partnumber are different, it will store the partnumber old the
old job in a TEMP location then continue looping in the inner loop to check
any other part number. A counter should be put there (TEMP), if not same,
count 1 and at the end, if the counter equals to the number of inner loop,
then move the value of the TEMP to the STRMYRECSET where it will be displayed
in message box.
So, after finishing the inner loop, the TEMP value should be erased to start
a new cycle of outer loop.....

I am not sure it will work or not so I need your guidance....
I am sorry, I am not good at coding, that is why need your help again...

Thanks Thanks...million of thanks
Option Compare Database

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
Dim strmyrecset As String
Dim strtemp 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
mySQL1 = "SELECT WIPRawDetails.PartNumber, W_KittedQTY FROM WIPRawDetails
WHERE WIPRawDetails.JobNumber='" & Me.txtJobNumberOld & "'"
       
       myrecset.Open mySQL1

   
   ' 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
       mySQL = "SELECT WIPRawDetails.PartNumber FROM WIPRawDetails WHERE
WIPRawDetails.JobNumber='" & Me.txtJobNumberNew & "'"
myrecset1.Open mySQL
       
       '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 job #:" & Me.
txtJobNumberNew
       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 =" & myrecset!
W_KittedQty
               mySQL2 = mySQL2 & " Where jobnumber= '" & Me.txtJobNumberNew
& "' AND partnumber ='" & myrecset1!PartNumber & "'"
               CurrentDb.Execute mySQL2, dbFailOnError
               '----Suggestion :- Go to the outer loop and move next
               '----Suggestion :- Else (if not same part number) store in a
temp place eg strtemp = myrecset!PartNumber...If the
               '----Suggestion :- count is equal to the number of loop then
move the part number to a new place :-
               '----Suggestion :- example strmyrecset = strtemp
               End If
               myrecset1.MoveNext
               
               
           Loop
           myrecset1.Close
         
           '---Suggestion :- clear the strtemp in order to move to the next
1
       
       End If
   myrecset.MoveNext
   Loop
   myrecset.Close
If Not IsNull(strmyrecset) Then
MsgBox "What Ever message here" & strmyrecset, vbInformation, "What ever"""

Else

MsgBox "Update has been completed"

End If
   Set myrecset1 = Nothing
   Set myrecset = Nothing
   

End Sub

>Hi Emily,
>
[quoted text clipped - 137 lines]
>
>>EMILYTAN wrote:
AccessVandal - 20 Jun 2007 11:46 GMT
Hi Emily,

That complicates things and makes the code difficult to read.

Anyway, Have you tried running the code? It is always good to test it first.

Air code here for you to try.

If you want to use GoTo.

OutLoopRec:  ‘place goto here
Do Until myrecset.EOF  ‘outer loop
‘what ever……
‘……………
Do Until myrecset1.EOF  ‘inner loop
                             '----Suggestion :- Go to the outer loop and
move next
GoTo OutLoopRec  'tell VB where to go, might go into a continuous loop

If you want to count.

Dim LngRecCount as Long

LngRecCount = myrecset.RecordsetCount ‘the total of records in this set

Use the loop the minus or plus to do count like

LngRecCount = -1 ‘to minus the total in above line
‘---------------------------------------------------------------------------

Or you can do just by counting the number of loops

Dim LngRecCount As Long

LngRecCount = LngRecCount + 1
‘use the loop to increase the counter

>EMILYTAN wrote:
>Hey,
[quoted text clipped - 22 lines]
>
>Thanks Thanks...million of thanks

Signature

Please Rate the posting if helps you

EMILYTAN - 21 Jun 2007 03:36 GMT
Ok...gonna try on it...thanks for helping

>Hi Emily,
>
[quoted text clipped - 38 lines]
>>
>>Thanks Thanks...million of thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.