473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Query criteria from Main Form

I have a main form with a text box on it "txtSearch" onlost focus it
updates another text box "txtSearchString" to include a quote and
asterik before and after the value of txtSeach.

I then have a query set to use forms!frmMain!txtSearchString as the
search criteria for a field. But it is not working. If I go and copy
the value of txtSearchString and paste it as cretieria in the query it
works but not live and dynamicly pulling it from the main form. My
criteria is set as

forms!frmMain!txtSearchString

and I even tried

= forms!frmMain!txtSearchString

Like forms!frmMain!txtSearchString

Any help is apreciated...

Dave

Oct 16 '06 #1
2 1966
I don't think you have provided enough detail to get a good answer.
Are you using a stored query, a temporary query or a query set in code?

You might try this. Set the module in the onclick event of a test button on
your form.
The button should do nothing else.

See if the output is what you are looking for.
Sub MyQueryTest()

Dim dbs As Object, rst As Object

Dim strSQL As String

Set dbs = CurrentDb()

strSQL = "Select Field1, Field2 " & _

"From tblOfInterest " & _

"Where Field1 Like *" & forms!frmMain!txtSearchString & "* ; "

Set rst = dbs.OpenRecordset(strSQL)

With rst

Do While Not .EOF()

Debug.print Field1

.MoveNext

Loop

End With

Set rst = nothing

Set dbs = nothing

End Sub

This way you know that the form is open when the query is invoked and thus
the txtBox's value is available.

Also the Like function needs to have a "quote" , "asterik" before and
"asterik" "quote" after.

Good luck or post better question.

<st********@hotmail.comwrote in message
news:11*********************@k70g2000cwa.googlegro ups.com...
>I have a main form with a text box on it "txtSearch" onlost focus it
updates another text box "txtSearchString" to include a quote and
asterik before and after the value of txtSeach.

I then have a query set to use forms!frmMain!txtSearchString as the
search criteria for a field. But it is not working. If I go and copy
the value of txtSearchString and paste it as cretieria in the query it
works but not live and dynamicly pulling it from the main form. My
criteria is set as

forms!frmMain!txtSearchString

and I even tried

= forms!frmMain!txtSearchString

Like forms!frmMain!txtSearchString

Any help is apreciated...

Dave

Oct 16 '06 #2
st********@hotmail.com wrote:
I have a main form with a text box on it "txtSearch" onlost focus it
updates another text box "txtSearchString" to include a quote and
asterik before and after the value of txtSeach.
No, don't do that. It's not how to use a wildcard.

I do something very similar to what you describe, EXCEPT I use the on
change event. In that event, I have:

Private Sub txtSearch_Change()
Me.txtSearchString = Me.txtSearch.Text
me.requery
End Sub

In the query that is the recordsource for your form, the criteria should be:

"*" & forms!frmMain!txtSearchString & "*"

for the query field CONTAINS the search string or

"*" & forms!frmMain!txtSearchString

for the query field ENDS WITH the search string or

forms!frmMain!txtSearchString & "*"

for the query field STARTS WITH the search string.

The requery is necessary to tell the form to check its recordsource query.

By doing the above in the on change event, you'll also see your results
narrow down with every letter entered into the txtSearch box.

BTW, I always have txtSearchString a hidden control, so the user only
sees what s/he is entering into the txtSearch control.

--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Oct 17 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: William Wisnieski | last post by:
Hello Everyone Access 2000 Looking for some suggestions and advice on how to proceed with this. I hope its not as complicated as it seems to me right now. I've got an unbound main form...
3
by: John young | last post by:
I have been looking for an answer to a problem and have found this group and hope you can assist . I have been re doing a data base I have made for a car club I am with and have been trying to...
6
by: Liz Malcolm | last post by:
Hello and Thanks in advance for any help. I am using Access 2000. I have a data entry form that opens a main form (using the On Click event of the combo box ) with tab controls and 1 subform on...
14
by: Darin | last post by:
I have a table that I want to delete specific records from based on data in other tables. I'm more familiar with Access '97, but am now using 2003, but the database is in 2000 format. In '97, I...
7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: stevecat | last post by:
Hi there, I have created a form, "search" and a query "search_product". The query returns the product information based upon the criteria for three of the fields, author, title or isbn. The field...
1
by: tomlebold | last post by:
Having problems displaying query results from combo boxes on a sub form, which is on the same form that is used to select criteria. This has always worked form me when displaying query results on...
6
by: jmarcrum | last post by:
Hi! I have created a Union Query in ACCESS 2003, that combines 130 records from one query (Extra Foreman Radios) and 250 records from another query (Forman Main Radios). I have created a...
0
Walt in Decatur
by: Walt in Decatur | last post by:
I have a form which is tied to a table with data for equipment belonging in a particular space (tbl_equpment_data). This form is actually a subform on a main form which also deals with other data...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.