View Full Version : Query criteria from a form


Henley12
02-28-2008, 05:52 AM
I have a form I am using to either select an Equipment ID or pull all records if no id is selected. My code in the query looks like the following:

([Forms]![frmWOCommentRpt]![cboEquipID]) Or Like "**"


When I run this, however, it only does the Or part. If I select an equipment ID on the form, it doesn't just pull that. I'm sure this is a simple fix, but I can't see it. Any ideas?

Brianwarnock
02-28-2008, 06:11 AM
As the Like will always be true it will always be actioned.
If you do not require to select Null values try
Like "*" & [Forms]![frmWOCommentRpt]![cboEquipID]) & "*"
you may also like to see this thread.
http://www.access-programmers.co.uk/forums/showthread.php?t=103312&highlight=query+form

Brian

Henley12
02-28-2008, 06:29 AM
Thank you. I have that one working now. In the same form and query, however, I have two date fields that may be selected. The user may select either date field, but not both, with an option button. How can I make my query select records based on the date field selected and if the from and to dates are left blank, pull all records (of the selected date field)? That sounds mighty confusing, doesn't it? Here is the code I have in my query. This is just for the Due By date field. Would I need something similar for the Completed By date field?

IIf([Forms]![frmWOCommentRpt]![txtDate]="DueBy",[tblMain]![DueBy] Between [Forms]![frmWOCommentRpt]![txtFromDt] And [Forms]![frmWOCommentRpt]![txtToDt],[tblMain]![DueBy] Between #1/1/1900# And #12/31/2099#)

Brianwarnock
02-28-2008, 08:02 AM
You do not put that in the criteria of your dueby field.
Switch to SQL view and in the Where clause

Where IIf([Forms]![frmWOCommentRpt]![txtDate]="DueBy",[tblMain]![DueBy] Between [Forms]![frmWOCommentRpt]![txtFromDt] And [Forms]![frmWOCommentRpt]![txtToDt],[tblMain]![completedby] Between [Forms]![frmWOCommentRpt]![txtFromDt] And [Forms]![frmWOCommentRpt]![txtToDt])

I have assumed that they can only select DueBy and CompletedBy

Brian