By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

syntax error in select query

P: 44
sir,
suppose if the question is how many stations are there ,then if i give some word matching the question in table in the textbox named keyword ,i want to get that question
docmd.applyfilter "SELECT tblexam.* FROM tblexam WHERE tblexam.question like ' * '" & [Forms]![frmsetquestions]!keyword & "' * ' "
please help me
thanks in advance
May 10 '07 #1
Share this Question
Share on Google+
9 Replies


Expert
P: 97
sir,
suppose if the question is how many stations are there ,then if i give some word matching the question in table in the textbox named keyword ,i want to get that question
docmd.applyfilter "SELECT tblexam.* FROM tblexam WHERE tblexam.question like ' * '" & [Forms]![frmsetquestions]!keyword & "' * ' "
please help me
thanks in advance
You appear to be misusing Applyfilter

Expand|Select|Wrap|Line Numbers
  1. DoCmd.ApplyFilter(Queryname)
or

Expand|Select|Wrap|Line Numbers
  1. DoCmd.ApplyFilter , "[question] like ' * '" & [Forms]![frmsetquestions]!keyword & "' * ' "
May 10 '07 #2

P: 44
SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.question like ' * '" & [Forms]![frmsetquestions]!keyword & "' * '"
DoCmd.ApplyFilter SrcSQL4
still giving syntax error.
please help me
May 10 '07 #3

Expert
P: 97
SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.question like ' * '" & [Forms]![frmsetquestions]!keyword & "' * '"
DoCmd.ApplyFilter SrcSQL4
still giving syntax error.
please help me
You must use a SAVED query or just the WHERE clause (but without the WHERE keyword).
May 10 '07 #4

P: 44
that query sntax is wrong sir
thats what i am asking.
please tell the correct query
May 10 '07 #5

Expert
P: 97
Try putting a semi-colon ; at the end of the statement within your quotes
May 10 '07 #6

JConsulting
Expert 100+
P: 603
that query sntax is wrong sir
thats what i am asking.
please tell the correct query

How about

Expand|Select|Wrap|Line Numbers
  1. "SELECT tblexam.*, tblexam.question FROM tblexam WHERE tblexam.question like * '" & [Forms]![frmsetquestions]!keyword & "'*;"
  2.  
May 10 '07 #7

P: 44
sir,
i wrote what u told.
but still it is giving syntax error. My head is killing.
From 3days i am working on that query.
please help me.
what i tried is
SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.question like * '" & [Forms]![frmsetquestions]!keyword & "'*;"
SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.question like ' * '" & [Forms]![frmsetquestions]!keyword & "'* ';"
SrcSQL4 = "SELECT tblexam.* FROM tblexam WHERE tblexam.question like "* '" & [Forms]![frmsetquestions]!keyword & "'*";"
DoCmd.ApplyFilter (SrcSQL4)
with out semicolon at the end, also i tried all above
thanks in advance
May 11 '07 #8

Expert
P: 97
This works for me:
Expand|Select|Wrap|Line Numbers
  1. SrcSQL4 = "SELECT services.* FROM services WHERE services.[service performed] like '* " _
  2.         & [Forms]![services1]![keyword] & " *'"
  3. DoCmd.ApplyFilter SrcSQL4
  4.  
I created a new form in my database, pasted your code into it and changed table, field and form names.
No syntax error. The query did not find what I searched for, so I tidied up the spaces and quotes, and now it finds the word in the keyword textbox. I tried the filter on both a text field and a memo field with success.
I am using Access 2003, but I doubt that will affect it.
May 11 '07 #9

P: 44
sir,
thank u very much for ur help.
i got it finally.
May 11 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.