PDA

View Full Version : Creating a search query.



kbsudhir
04-14-2008, 03:12 PM
Hi All,

I want to create a query to seach the data in a particular column in the table.

Ex. Column "Subject"

The parameter for search should be dynamic & should prompt the user to enter the word to search.

I cab easily create an static query using Where condition & like clause

where Like *SBC*

I was even able to get the prompt where user can insert the word to be searched.

[Enter the word to be searched] but I was not able to pass the word as the parameter to teh query.

The word should be accepted between Like *value entered*

Please guide me this.

Thanks
Sudhir

Trevor
04-14-2008, 08:55 PM
It is a little unclear what you realy have going on so here are a few suggestions:
if your passing a single value to a query, not you can also use this example for passinging multiple variables , assuming query is query1 and the form your passing from is form1 and the textbox is text then

DoCmd.Runsql Select from from tablename [field1],[field2]
Where Field1 = Forms!Form1!Text

or you can pass the value you want to pass to a query by using an operator ie <, >, =, <> '" & variableName & "'
Hope this helps

kbsudhir
04-15-2008, 05:02 AM
Thanks Trevor.

Right now I am not attaching the query to form.

I just creating simple query in access. What I am trying to do as soon as I click on that query it should prompt me to enter the word which i want to search.

I created a query where the I am getting a prompt to enter the desired date to pull the data for that particular date. I am attaching the query for that.
i.e.
SELECT Outlook.Subject, Outlook.MessageBody, Outlook.To, Outlook.CC, Outlook.Importance, Outlook.From, Outlook.ReceivedDateTime
FROM Outlook
WHERE (((Int([ReceivedDateTime]))=[Insert Date]))
GROUP BY Outlook.Subject, Outlook.MessageBody, Outlook.To, Outlook.CC, Outlook.Importance, Outlook.From, Outlook.ReceivedDateTime
ORDER BY Outlook.ReceivedDateTime DESC;

I used the same concept get the word to be searched from the user
but it is not working.In this case I used the where condition on Subject field.

I hope I am lot clearer now.

But once again for thanks for your above suggestion as it will going to help me down teh line.

Thanks
Sudhir

:bow:

Trevor
04-15-2008, 02:50 PM
Then just in your crtera field ie
Date = (stvar)
then you will be propted to enter the value for stvar
you can also change stvar to anthing you like,
hope this is what your looking for

kbsudhir
04-18-2008, 05:31 AM
Thansk Trevor for all your time.

But I think Iam just not clearly mentioning want exactly I am trying.
My Mistake And No Excuses.

I am trying to create a dynamic query which will search for the word or characters (in nay combination) entered by the user in runtime to the query(when prompted by the query for the parameter) in Subject filed of teh table and then pull the data accordingly.

I hope this time I am clear but please feel free if I am still creating confusion.

Thanks for all the precious time you have spent on my query.

Sudhir
:bow:

ben.oates
04-18-2008, 06:33 AM
SELECT field1, field2, field3, etc FROM table WHERE fieldx LIKE "*" & [Enter the word to be searched] & "*";

This will search for a specific string in fieldx with any characters to the right or left of that string in the same fieldx.

Hope this helps kbsudhir.

Trevor
04-18-2008, 03:14 PM
or if you want to serch by parchial string for field 1 you as select query with
intstr(field1, '" & yourvariablestringhere) & '"

to search for a field 1 containing the chartchurs ip the string

rangudu_2008
05-25-2008, 06:11 AM
Hi,
Try using this form in ur Access application...