DCount problem

trucktime

Registered User.
Local time
Today, 14:12
Joined
Oct 24, 2004
Messages
556
In the After Update Event of the field Lastname I have some code to check
if a person with that First- and Last name already exists in the database:

If DCount("*", "[tblPeople]", "[LastName]= '" & Me.LastName & "' And [Firstname] = '" & Me.FirstName & "'") Then
Beep
MsgBox "This name already exists in the database!" & vbCrLf & " Please check for duplicate entry.", vbExclamation, ""
Me.Undo
Cancel = True

This works just fine, but the problem starts when the Lastname is something
like: O'Leary.
Then I get this error:

Syntax Error(Missing Opererator) in Query Expression '[Lastname] = 'O'Leary'
and [Firstname] = 'John".


Obviously it is the ' that is causing the problem.
Any solution for this?

Thank you all.
 
Last edited:
Trucktime,

The Replace function is handy for this type of thing:

Code:
If DCount("*", "[tblPeople]","[LastName]= '" & Replace(Me.LastName, "'", "''") & "' And [Firstname] = '" & Me.FirstName & "'") Then
    Msgbox "Etc"
End if

Regards,
Tim
 
DCount

That works great!

Thanks Pono1 :)
 

Users who are viewing this thread

Back
Top Bottom