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

Using Dynamic Query - Would Like to Search Check Box from table

Status
Not open for further replies.

elevins

Technical User
Jan 24, 2005
18
Can anyone help me?

I am using Dynamic Query, it is run when a click a command button. All the text boxes are working fine but I would like to use check boxes to search also. I am having trouble finding any info on how to search using a check box.

Here is an example of what code I am using:

Private Sub cmdRunQuery_Click()
Dim db As DAO.Database
Dim QD As QueryDef
Dim where As Variant

Set db = CurrentDb()


On Error Resume Next
db.querydefs.Delete ("Dynamic_Query")
On Error GoTo 0

where = Null
where = where & " AND [Inventory]like '" + Me![Inventory] + "*'"
where = where & " AND [SerialNum]like '" + Me![SerialNum] + "*'"
where = where & " AND [Description]like '" + Me![Description] + "*'"
where = where & " AND [Mfg]like '" + Me![Mfg] + "'"
where = where & " AND [ModelNum]like '" + Me![ModelNum] + "*'"
where = where & " AND [Cost]like '" + Me![Cost] + "'"
where = where & " AND [CaseNum]like '" + Me![CaseNum] + "*'"
where = where & " AND [Remarks]like '" + Me![Remarks] + "*'"
where = where & " AND [Date]like '" + Me![Date] + "*'"
' Where = Where & " AND [Stored]= '" + Me![Stored] + "'" ' this is the checkbox - yes/no there will be three more check boxes


Set QD = db.CreateQueryDef("Dynamic_Query", _
"Select * from SearchQueryBase " & (" where " + Mid(where, 6) & ";"))
DoCmd.OpenQuery "Dynamic_Query"
End Sub
 
Where = Where & " AND [Stored]= " + Me![Stored]

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
I tried this and does not seem to work for my searching of a Checkbox. Do you have any other ideas?
 
Anybody's help would be much appreciated. This is the only problem I am stuck on with my database.
 
And something like this ?
Where = Where & " AND [Stored]=" & IIf(Me![Stored], "True", "False")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Great! That helped out a lot. Thanks.

Where = Where & " AND [Stored]=" & IIf(Me![Stored], "True", "False")

As you can probably tell I am not great with this code but I am learning quickly.

The problem now is that it only will work corectly for the feild "Stored". If I code the other fields say "Junk" and "Stolen" They will not work together. I will recieve a "Invalid use of Null" error.

Is there an "OR" statement or something else that could solve this problem?

This is the current code I have, any suggestions would help.


where = Null
where = where & " AND [Inventory]like '" + Me![Inventory] + "*'"
where = where & " AND [SerialNum]like '" + Me![SerialNum] + "*'"
where = where & " AND [Description]like '" + Me![Description] + "*'"
where = where & " AND [Mfg]like '" + Me![Mfg] + "'"
where = where & " AND [ModelNum]like '" + Me![ModelNum] + "*'"
where = where & " AND [Cost]like '" + Me![Cost] + "'"
where = where & " AND [CaseNum]like '" + Me![CaseNum] + "*'"
where = where & " AND [Remarks]like '" + Me![Remarks] + "*'"
where = where & " AND [Date]like '" + Me![Date] + "*'"

where = where & " AND [Junk]=" & IIf(Me![Junk], "True", "False")
where = where & " AND [Stored]=" & IIf(Me![Stored], "True", "False")
where = where & " AND [Stolen]=" & IIf(Me![Stolen], "True", "False")






 
Once I check a box like "Stored" and then unckeck it It changes the Dynamic Query to False and stays that way until I close the Form. Is there a way to have it "clear" the check box after deselection?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top