-
May 29th, 2009, 07:07 AM
#1
[RESOLVED] Syntax error ( missing operator ) in query expression
Hello guys,
I am getting this error message:
Syntax error (missing operator ) in query expression ' PatientNumber = "
The code is as follows:
Set rs = con.Execute("Select * from Patients where PatientNumber =" & txtnumb & "")
If rs.EOF = True Then
Else
txtfullname = rs!Fullname
txtnumb = rs!PatientNumber
End If
Set con = Nothing
-
May 29th, 2009, 08:20 AM
#2
Re: Syntax error ( missing operator ) in query expression
Before generating the query you should check for the value in the txtNumb text box. It seems like you are passing an empty value to the query because of which it is failing.
Also remember, it is always better to use parameterized queries. Search the forum for these.
Also, please use code tags when you are posting sourcecode in the forum. Look at our FAQ on how to use the code tags.
-
May 29th, 2009, 08:56 PM
#3
Re: Syntax error ( missing operator ) in query expression
Code:
>Set rs = con.Execute("Select * from Patients where PatientNumber =" & txtnumb & "")
If it is a number then...
Code:
Set rs = con.Execute("Select * from Patients where PatientNumber =" & txtnumb)
but if it is text then...
Code:
Set rs = con.Execute("Select * from Patients where PatientNumber ='" & txtnumb & "'")
Good Luck
-
May 29th, 2009, 11:26 PM
#4
Re: Syntax error ( missing operator ) in query expression
That is if the field in the database is defined as a number or is defined as text. If the field is defined as text you must use the 's even if the value is a number.
-
June 2nd, 2009, 02:31 AM
#5
Re: Syntax error ( missing operator ) in query expression
The field in the database is defined as a number with no duplicates. i have tried removing the 's
but it still gives me the same error message
-
June 2nd, 2009, 03:00 AM
#6
Re: Syntax error ( missing operator ) in query expression
Hey guys
i tried to change the field in the database to text and put the following code:
Set rs = con.Execute("Select * from Patients where PatientNumber ='" & txtnumb & "'")
this code runs well. but i want in the field txtnumb to accept numbers only as i have specified in the database with no duplicates. i dont want the numbers in that field to be repeated.
thank you in anticipation
-
June 2nd, 2009, 05:43 PM
#7
Re: Syntax error ( missing operator ) in query expression
Set it as a AUTONUMBER field, and use it as a key. Enter the date/time entered into this db as well
(I like a DELETED field as well)
-
June 2nd, 2009, 10:57 PM
#8
Re: Syntax error ( missing operator ) in query expression
Originally Posted by vb5prgrmr
Code:
>Set rs = con.Execute("Select * from Patients where PatientNumber =" & txtnumb & "")
If it is a number then...
Code:
Set rs = con.Execute("Select * from Patients where PatientNumber =" & txtnumb)
but if it is text then...
Code:
Set rs = con.Execute("Select * from Patients where PatientNumber ='" & txtnumb & "'")
If it is a number then...
Code:
Set rs = con.Execute("Select * from Patients where PatientNumber =" & val(txtnumb))
would be better, if txtnumb is empty then '0' value is passed to query.
Encourage the efforts of fellow members by rating
Lets not Spoon Feed and create pool of lazy programmers
- ComIT Solutions
-
June 4th, 2009, 02:07 AM
#9
Re: Syntax error ( missing operator ) in query expression
Thanks COMITSolution for all your help.
This solutions worked out fine :
If it is a number then...
Code:
Set rs = con.Execute("Select * from Patients where PatientNumber =" & val(txtnumb))
and thanks to all of you guys. i appreciate all the help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|