Hello,
can someone help me with this code, I am having trouble making recordsets for it
Cheers
can someone help me with this code, I am having trouble making recordsets for it
Code:
Private Sub Command0_Click()
volstring = Null 'String to hold the volunteers that have been processed
DoCmd.SetWarnings False
'Cretae a loop, we'll do our own exit condition later
Do While 1 = 1
'If the volString is not empty, we check for volunteers NOT processed
If IsNull(volstring) = False Then
getVol = DLookup("Volunt_Id", "volunteer", "Volunt_Id NOT IN (" & volstring & ")")
'If the volString is empty, we check for the first volunteer
Else
getVol = DLookup("Volunt_Id", "volunteer")
End If
'If we cant find any more we exit the loop
If IsNull(getVol) = True Then
Exit Do
Else
'Lets get their first priority
check1 = DLookup("First_Choice", "tblChoice", "Volunt_Id = '" & getVol & "'")
'Now we check if it has been taken, or if their is no priority, assume it is taken
If IsNull(check1) = False Then
checktaken = DLookup("assignedto", "tblProject", "Project_Id = '" & check1 & "'")
Else
checktaken = Null
End If
'If it is not taken
If IsNull(checktaken) = True Then
'Add it to the table
DoCmd.RunSQL ("UPDATE volunteer SET assignedto = '" & getVol & "' WHERE Project_Id = '" & check1 & "'")
Else
'we check for thier second one
check1 = DLookup("Second_Choice", "tblChoice", "Volunt_Id = '" & getVol & "'")
'Now we check if it has been taken, or if their is no priority, assume it is taken
If IsNull(check1) = False Then
checktaken = DLookup("assignedto", "tblProject", "Project_Id = '" & check1 & "'")
Else
checktaken = Null
End If
If IsNull(checktaken) = True Then
'Add it to the table
DoCmd.RunSQL ("UPDATE volunteer SET assignedto = '" & getVol & "' WHERE Project_Id = '" & check1 & "'")
Else
'we check for their third one
check1 = DLookup("Third_Choice", "tblChoice", "Volunt_Id = '" & getVol & "'")
'Now we check if it has been taken, or if their is no priority, assume it is taken
If IsNull(check1) = False Then
checktaken = DLookup("assignedto", "tblProject", "Project_Id = '" & check1 & "'")
Else
checktaken = Null
End If
If IsNull(checktaken) = True Then
'Add it to the table
DoCmd.RunSQL ("UPDATE volunteer SET assignedto = '" & getVol & "' WHERE Project_Id = '" & check1 & "'")
Else
'NOTE: This is your code for what to do if ALL their priorities have been taken
End If
'Now we add the volunteer to the list we dont process
volstring = volstring & "'" & getVol & "',"
Loop
DoCmd.SetWarnings True
End Sub
Cheers