I have created a rotation log for selecting wreckers, when i get to the last wrecker it will not return back to the first wrecker in the rotation, I am missing something any HELP?
Code:
'Setup variables for holding unique id place holder
Dim tsLastRecordID As Integer
Dim cfsLastRecordID As Integer
Dim wrckLastRecordID As Integer
Dim wrckFirstRecordID As Integer
Dim tsLstWreckerID
Dim cfsLstWreckerID
'First Get all the last record's on the table ID
'Getting Last Record I can check the columnd that contains the last used wrecker id
tsLastRecordID = DMax("ID", "TS")
csfLastRecordID = DMax("ID", "CFS")
wrckLastRecordID = DMax("ID", "Wreckers")
'If I don't get wrecker id I need the first one to get its name on the if statement...
wrckFirstRecordID = DMin("ID", "wreckers")
'Used the last ID from previous to get the WreckerID field..
tsLstWreckerID = DLookup("[WreckerID]", "TS", "[ID] = " & tsLastRecordID)
cfsLstWreckerID = DLookup("[WreckerID]", "CFS", "[ID] = " & csfLastRecordID)
'Here we going to check what to display on the user screen
'If there hasnt been a previous wrecker id thenwe starting from the first wrecker..
If IsNull(tsLstWreckerID) And IsNull(cfsLstWreckerID) Then
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
ElseIf IsNull(cfsLstWreckerID) Then
If tsLstWreckerID = wrckLastRecordID Then
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
Return 'Kills Operations
End If
tsLstWreckerID = tsLstWreckerID + 1
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & tsLstWreckerID)
ElseIf IsNull(tsLstWreckerID) Then
If cfsLstWreckerID = wrckLastRecordID Then
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
Return 'Kills Operations
End If
cfsLstWreckerID = cfsLstWreckerID + 1
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & cfsLstWreckerID)
ElseIf tsLstWreckerID < cfsLstWreckerID Then
'If the last wrecker equals the last of the list then go back to one..
If cfsLstWreckerID = wrckLastRecordID Then
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
Return
End If
cfsLstWreckerID = cfsLstWreckerID + 1
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & cfsLstWreckerID)
ElseIf cfsLstWreckerID < tsLstWreckerID Then
'If the last wrecker equals the last of the list then go back to one..
If tsLstWreckerID = wrckLastRecordID Then
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & wrckFirstRecordID)
Return
End If
tsLstWreckerID = tsLstWreckerID + 1
asswrecker.Value = DLookup("[Wrecker Company]", "Wreckers", "[ID] = " & tsLstWreckerID)
End If
Comment