W
Wayne Emminizer
Hopefully a quick question on For Next loop function. I
have the code below. Basically I want this to check the
item code field for the current ID in the loop and make
sure it exists. There are times when the next ID won't
exist such as when I put a filtered set of records in
this table and the ID's are not sequential. In this
event I need for the code to go back to the top and go to
the next ID and test it. If the item code is not null
then it needs to run the code. It is working in it's
present form but I think it's not working correctly...I
am still trying to validate that.
lngMin = DMin("[ID]", TempTable)
lngMax = DMax("[ID]", TempTable)
Counter = lngMin
For Counter = lngMin To lngMax Step 1
If IsNull(DLookup("[ItemCode]", TempTable, "[ID]
=" & Counter & "")) Then
Counter = Counter + 1
Else
ActiveItemCode = DLookup("[ItemCode]",
TempTable, "[ID]=" & Counter & "")
ActiveOriginCompany = DLookup
("[OriginCompany]", TempTable, "[ID]=" & Counter & "")
'******There is a section here that runs a ton of code I
am not copying up since it would take too much space***
End If
DoCmd.RunSQL "UPDATE [TEST] SET
[TEST].NewItemName='" & sqlString & "'" & " WHERE [ID]="
& Counter & ";"
'DoCmd.RunSQL "UPDATE [vueItemMaster] SET
[vueItemMaster].NewItemName='" & ActiveItemCode & " " &
ActiveOriginCompany & "'" & " WHERE [ID]=" & Counter & ";"
Next Counter
have the code below. Basically I want this to check the
item code field for the current ID in the loop and make
sure it exists. There are times when the next ID won't
exist such as when I put a filtered set of records in
this table and the ID's are not sequential. In this
event I need for the code to go back to the top and go to
the next ID and test it. If the item code is not null
then it needs to run the code. It is working in it's
present form but I think it's not working correctly...I
am still trying to validate that.
lngMin = DMin("[ID]", TempTable)
lngMax = DMax("[ID]", TempTable)
Counter = lngMin
For Counter = lngMin To lngMax Step 1
If IsNull(DLookup("[ItemCode]", TempTable, "[ID]
=" & Counter & "")) Then
Counter = Counter + 1
Else
ActiveItemCode = DLookup("[ItemCode]",
TempTable, "[ID]=" & Counter & "")
ActiveOriginCompany = DLookup
("[OriginCompany]", TempTable, "[ID]=" & Counter & "")
'******There is a section here that runs a ton of code I
am not copying up since it would take too much space***
End If
DoCmd.RunSQL "UPDATE [TEST] SET
[TEST].NewItemName='" & sqlString & "'" & " WHERE [ID]="
& Counter & ";"
'DoCmd.RunSQL "UPDATE [vueItemMaster] SET
[vueItemMaster].NewItemName='" & ActiveItemCode & " " &
ActiveOriginCompany & "'" & " WHERE [ID]=" & Counter & ";"
Next Counter