Syntax error (missing operator) in expression

N

Nick T

Hi,
I have the following code in the 'on click' event of a command button on a
form. Also on the form are text boxes. I want to type a 'post code' into my
relevant text box, click my 'find' button, and the associated info (which is
in my table) to be put into the other relevant text boxes.
This is my code:

Private Sub Command9_Click()
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("Addresses", dbOpenDynaset)
With rst
.FindFirst "[PostalCode] = " & Me.PostalCode

If .NoMatch Then
MsgBox "Post Code " & Me.PostalCode & " Not Found in Client list"
Else
Me.FirstName = !FirstName
Me.LastName = !LastName
Me.CustomerID = !CustomerID

End If

.Close
End With
Set rst = Nothing

End Sub

However, i have a Syntax error with the following in the above code.
..FindFirst "[PostalCode] = " & Me.PostalCode

Any suggestions??

Many thanks
 
B

Beetle

Is your Postal Code field a text data type? If so it should be;

..FindFirst "[PostalCode] = """ & Me.PostalCode & """"

to clarify that's three double quotes after "[PostalCode] =
and four double quotes at the end.
 
N

Nick T

Excellent!
Thanks for that - thought it could be somthing relatively simple.


Beetle said:
Is your Postal Code field a text data type? If so it should be;

.FindFirst "[PostalCode] = """ & Me.PostalCode & """"

to clarify that's three double quotes after "[PostalCode] =
and four double quotes at the end.
--
_________

Sean Bailey


Nick T said:
Hi,
I have the following code in the 'on click' event of a command button on a
form. Also on the form are text boxes. I want to type a 'post code' into my
relevant text box, click my 'find' button, and the associated info (which is
in my table) to be put into the other relevant text boxes.
This is my code:

Private Sub Command9_Click()
Dim rst As DAO.Recordset

Set rst = CurrentDb.OpenRecordset("Addresses", dbOpenDynaset)
With rst
.FindFirst "[PostalCode] = " & Me.PostalCode

If .NoMatch Then
MsgBox "Post Code " & Me.PostalCode & " Not Found in Client list"
Else
Me.FirstName = !FirstName
Me.LastName = !LastName
Me.CustomerID = !CustomerID

End If

.Close
End With
Set rst = Nothing

End Sub

However, i have a Syntax error with the following in the above code.
.FindFirst "[PostalCode] = " & Me.PostalCode

Any suggestions??

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top