Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using criteria in form text box or using *

Status
Not open for further replies.

Badly

MIS
Oct 15, 2002
4
GB
I can't work out how to get a simple query to read a value from a text box on a form or to default to "*" (or blank i.e. no criteria) if the text box is left blank by the user.

I'm trying to use the form as a point where my users can enter criteria values for the query to use e.g.

[Forms]![frm (analysisreports)]![deftype]

or leave blank. Trouble is if they leave the text box blank the query then applies the blank text field as a criteria value. I've tried setting the default value for the text box to "*" or Like "*" but the query doesn't read these text values in correctly as criteria.

I'm sure this must be simple to do but I can't see how! All suggestions very welcome (apart from "go on a course" !!)

Badly.
 
In this situation I'd suggest

If IsNull([deftype]) Then
' form of Query here that copes with Null
strSQL = "SELECT * FROM tblXYZ"
Else
' form of Query here that copes with data
strSQL = "SELECT * FROM tblXYZ WHERE fieldName LIKE '*" & deftype & "*';"
End If



'ope-that-'elps.




G LS
accessaceNOJUNK@valleyalley.co.uk
Remove the NOJUNK to use.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top