Combo Box Selection To Run Report Problem

J

jutlaux

I have a form with a combo box on it where the user can select someone's name
and then hit a button to run a query that just shows records for the selected
person. That part works just fine, the problem I have is that sometimes you
want to see everyone and I am trying to make so that if the combo box is left
empty everyone is displayed, but if you don't select someone from the combo
box the report is empty when it runs.

Here is the what I have
Form -> "frmProgChangeLogSearch" with the following on it
Combo box ->"cboPlantEngineer", which does have the control source empty
Run query button -> "cmdSearchByName"

Query ->"qryChangeLogMain_Search"
In this query I have Field "strAssignedTo" that has the criteria
[Forms]![frmProgChangeLogSearch]![cboPlantEngineer]

The cmdSearchByName button code is:

Private Sub cmdSearchByName_Click()
On Error GoTo Err_cmdSearchByName_Click

Dim stDocName As String

stDocName = "qryChangeLogMain_Search"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdSearchByName_Click:
Exit Sub

Err_cmdSearchByName_Click:
MsgBox Err.Description
Resume Exit_cmdSearchByName_Click

End Sub

Thanks
 
T

Tammy F

This may be an incomplete answer for what you are looking for... but in the
query your criteria could be for the search field:
[Forms]![frmProgChangeLogSearch]![cboPlantEngineer] or
[Forms]![frmProgChangeLogSearch]![cboPlantEngineer] is null

if the combo box is blank - then it will pull all the names.

Tammy
 
J

jutlaux

This is exaclty what I was looking for. Thanks!

Tammy F said:
This may be an incomplete answer for what you are looking for... but in the
query your criteria could be for the search field:
[Forms]![frmProgChangeLogSearch]![cboPlantEngineer] or
[Forms]![frmProgChangeLogSearch]![cboPlantEngineer] is null

if the combo box is blank - then it will pull all the names.

Tammy

jutlaux said:
I have a form with a combo box on it where the user can select someone's name
and then hit a button to run a query that just shows records for the selected
person. That part works just fine, the problem I have is that sometimes you
want to see everyone and I am trying to make so that if the combo box is left
empty everyone is displayed, but if you don't select someone from the combo
box the report is empty when it runs.

Here is the what I have
Form -> "frmProgChangeLogSearch" with the following on it
Combo box ->"cboPlantEngineer", which does have the control source empty
Run query button -> "cmdSearchByName"

Query ->"qryChangeLogMain_Search"
In this query I have Field "strAssignedTo" that has the criteria
[Forms]![frmProgChangeLogSearch]![cboPlantEngineer]

The cmdSearchByName button code is:

Private Sub cmdSearchByName_Click()
On Error GoTo Err_cmdSearchByName_Click

Dim stDocName As String

stDocName = "qryChangeLogMain_Search"
DoCmd.OpenQuery stDocName, acNormal, acEdit

Exit_cmdSearchByName_Click:
Exit Sub

Err_cmdSearchByName_Click:
MsgBox Err.Description
Resume Exit_cmdSearchByName_Click

End Sub

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top