Discussion Locked

Access 2000 Check for Duplicate Names

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have used this code in Access 97 databases and it works! It checks the lastname and first name. If both are identical you get an error message.

I copied and pasted it into Access 2000 and I keep getting an error message.

Error: Syntax Error(Missing Operator) in expression
on the line: rst.FindFirst strFind1

The code I am using is:

'Routine to check for Duplicate Name when entering NEW Name
Dim rst As Recordset
Dim db As Database
Dim strFind1 As String
Dim strFind2 As String

Set rst = Me.RecordsetClone

strFind1 = "Last Name = '" & Me.[Last Name] & "'"
strFind2 = "First Name = '" & Me.[First Name] & "'"

rst.FindFirst strFind1
rst.FindFirst strFind2

If Not rst.NoMatch Then
MsgBox " DUPLICATE!!!!!!!!!"

Me.Undo

Else

MsgBox "NO DUPLICATE FOUND!!!!"

End If

End Sub

3 replies

by techrep

Problems like this sometimes occur when you try to access the form's values directly. Try moving the form value into a string variable first:

Dim Lname as string
Lname = Me.[Last Name] & ""
strFind1 = "Last Name = '" & Lname & "'"

This discussion is closed to new replies.