Problems with VBA select query (1 Viewer)

Eric the Viking

Registered User.
Local time
Today, 15:44
Joined
Sep 20, 2012
Messages
70
Dear All
I am trying to use this code in a new database having used it in another to generate a list of records in an unbound list box (ListContacts) by typing the record number or surname in an unbound control (TextSurname):

Private Sub TextSurname_AfterUpdate()
If IsNumeric(Me.TextSurname) Then
ListContacts.RowSource = "Select tblContacts.ContactRegNo,tblContacts.Surname,tblContacts.Firstname,tblContacts.Address1,tblContacts.AddressPostcode," & _
"FROM tblContacts " & _
"WHERE tblContacts.ContactRegNo = " & TextSurname.Value & _
"ORDER BY tblContacts.FirstName;"

Else
ListContacts.RowSource = "Select tblContacts.ContactRegNo,tblContacts.Surname,tblContacts.Firstname,tblContacts.Address1,tblContacts.AddressPostcode," & _
"FROM tblContacts " & _
"WHERE tblContacts.Surname Like '*" & TextSurname.Value & "*' " & _
"ORDER BY tblContacts.FirstName;"

End If

End Sub

This is the error message I get:

"The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect"


Having spent a goodly while checking and double checking I cant work out why the method works in one database but not the other.....

Help would be much appreciated!

Cheers

Eric
 

jdraw

Super Moderator
Staff member
Local time
Today, 10:44
Joined
Jan 23, 2006
Messages
15,414
You have an extra comma before FROM.
Also watch your spacing, recommend you start or end each line with a space.


OOOps: Paul is quick!!
 

Eric the Viking

Registered User.
Local time
Today, 15:44
Joined
Sep 20, 2012
Messages
70
Many thanks I have no idea why I couldn't spot that! Exactly as I expected a fresh pair of eyes spotted the blindingly obvious! Many thanks Paul.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:44
Joined
Aug 30, 2003
Messages
36,139
Happy to help!
 

Users who are viewing this thread

Top Bottom