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

query about search button in my form

P: 44
sir,
i have a form exam created by using a table tblexam.In the tblexam fields are questionno,question,option1,option2,option3,option 4,answer fields.
In my form i have a question,option1,option2,option3,option4 textboxes having control sources from tblexam .Along with search command button and 1 unbound text box named text20.
If i enter some word in that text box and then click search then i want to get all the records matching that word in the table in the form.
If Me!Text20.Value <> "" Then
Dim dbss As DAO.Database
Dim rsts As DAO.Recordset
Set dbss = CurrentDb
SrcSQL3 = "SELECT tblexam.* FROM tblexam WHERE like tblexam.* like text20& " * ""
Set rsts = CurrentDb.OpenRecordset(SrcSQL3, dbOpenSnapshot)
If rsts.BOF And rsts.EOF Then
MsgBox "Questions not found , Please Try Again."
Else
questionno.setfocus
DoCmd.ApplyFilter SrcSQL3
rsts.Close
dbss.Close
End If

my problem is with SrcSQL3 select query statement.
please help me.
how to write the query
May 8 '07 #1
Share this Question
Share on Google+
5 Replies


Rabbit
Expert Mod 10K+
P: 12,366
A filter is only the WHERE clause of the SQL statement, without the word WHERE.
May 8 '07 #2

P: 44
i want to get all the records matching the text typed in the textbox named text20(say) from the table tblexam.
docmd.applyfilter SELECT tblexam.* FROM tblexam WHERE
please tell the WHERE condition
thanks in advance
May 9 '07 #3

Rabbit
Expert Mod 10K+
P: 12,366
From the help files:

The ApplyFilter method carries out the ApplyFilter action in Visual Basic.

expression.ApplyFilter(FilterName, WhereCondition)

expression Required. An expression that returns one of the objects in the Applies To list.

FilterName Optional Variant. A string expression that's the valid name of a filter or query in the current database. When using this method to apply a server filter, the FilterName argument must be blank.

WhereCondition Optional Variant. A string expression that's a valid SQL WHERE clause without the word WHERE.
May 9 '07 #4

P: 44
want to get all the records matching the text typed in the textbox named text20(say) from the table tblexam.
docmd.applyfilter "SELECT tblexam.* FROM tblexam WHERE tblexam.question like ' "Forms!frmsetquestions!text20 " ' "
with the above query i am not geting the required records.
suppose if the question is "what is speed" then in the textbox if i type speed i am not getting that question.If i give full question only in the textbox i am getting that record.
but i would like to give only some word in the question,i have to get the record.
please tell the WHERE condition how i have to modify
thanks in advance
May 9 '07 #5

Rabbit
Expert Mod 10K+
P: 12,366
You're looking for wildcard characters.

From the help files:

? or _ (underscore) = Any single character
* or % = Zero or more characters
# = Any single digit (0 9)
[charlist] = Any single character in charlist
[!charlist] = Any single character not in charlist
May 9 '07 #6

Post your reply

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