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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing '>' value into a query from TXT box

Status
Not open for further replies.

AT76

Technical User
Apr 14, 2005
460
US
Hi,

I have a table which the user needs to query it depending on criteria such as '>' or '<'. I have a txt box in my form called txtCriteria.

I have have a button which runs the query.

In the query under the column that I want the criteria set I write: [Forms]![FrmMain]![txtCriteria]

This works well if I enter a number. But when I enter a >50 I get the following error message:

Error 2001: You cancelled your previous operation.

Is there a way to avoid this?

Thank you!
 
I think you must use a little code, for example:
Code:
Dim strSQL As String
Dim qdf As QueryDef

'Build a query string using the data from your form
strSQL = "Select [i]Field1, Field2[/i] from [i]tblTable[/i] where [i]Field2[/i] " & [Forms]![FrmMain]![txtCriteria]

'Edit an existing query to change the SQL
Set qdf = CurrentDb.QueryDefs("[i]qryQuery[/i]")
qdf.SQL = strSQL

DoCmd.OpenQuery qdf.Name
 
sounds like your syntax is off, because your query is
parameterized?
?

When you enter ONLY a number, the filter becomes

txtWhatever "=" 49,

but you're trying to enter
txtWhatever "=>" 49

...or something along these lines.

...If your query is parameterized,
you may want to consider Remou's suggestion?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top