nakedbamboo
Technical User
I am trying to create some code that will search records to see if a person has already been input into the database. I have got the following code to do what I am trying to do, but I am curious if it is the most efficient way. I have a gut feeling it will be slow as the database becomes large. Is there any other way to do this?
Form name - Alumni
Field names - LastName and FirstName
The following code is in the Form_BeforeUpdate event:
If (Not IsNull(DLookup("[LastName]", _
"Alumni", "[LastName] ='" _
& Me!LastName & "'"
)) Then
If (Not IsNull(DLookup("[FirstName]", _
"Alumni", "[FirstName] ='" _
& Me!FirstName & "'"
)) Then
If MsgBox("This First and Last name have already been entered in the database. Do you wish to add this record?", vbYesNo, "Warning"
= vbNo Then
Cancel = True
Me.Undo
Else
End If
Else
End If
Else
End If
Form name - Alumni
Field names - LastName and FirstName
The following code is in the Form_BeforeUpdate event:
If (Not IsNull(DLookup("[LastName]", _
"Alumni", "[LastName] ='" _
& Me!LastName & "'"
If (Not IsNull(DLookup("[FirstName]", _
"Alumni", "[FirstName] ='" _
& Me!FirstName & "'"
If MsgBox("This First and Last name have already been entered in the database. Do you wish to add this record?", vbYesNo, "Warning"
Cancel = True
Me.Undo
Else
End If
Else
End If
Else
End If