If people are classified as a doctor, contractor, or guest I want the database to automatically to look for the next available number in their category and generate their number. I have the following code. But it isn’t working. Can someone help me. Thank you.
Private Sub txtClassification_AfterUpdate()
Dim NewID As String
Dim OldID As String
If txtClassification = “Doctor” Then
OldID = Nz(DMax(“Right(LearnerID,4)”, “tblLearners”, “left(LearnerID,1)=’D'”), “0000”)
NewID = Format(“DR-“) & Format(Right(OldID, 4) + 1, “0000”)
Me.LearnerID = NewID
ElseIf txtClassification = “Contractor” Then
OldID = Nz(DMax(“Right(LearnerID,4)”, “tblLearners”, “left(LearnerID,1)=’A'”), “0000”)
NewID = Format(“C-“) & Format(Right(OldID, 4) + 1, “0000”)
Me.LearnerID = NewID
ElseIf txtClassification = “Guest” Then
OldID = Nz(DMax(“Right(LearnerID,4)”, “tblLearners”, “left(LearnerID,1)=’G'”), “0000”)
NewID = Format(“G-“) & Format(Right(OldID, 4) + 1, “0000”)
Me.LearnerID = NewID
End If
End Sub
Fay