Prompt a user to select from a list as part of a query

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I want to create a query that prompts the user to select a type of work from
a drop down list and then runs the query. So,

--Prompt the user "Select a Type" from the following list:
---HVAC
UTILITES
ELECTRICAL
COMMUNICATIONS
VEHICLE MAINTENANCE
--User Selects "HVAC"
--QUERY creates a spreadsheet of all HVAC work types

Any help that you can give would be great. I'm novice. . .please explain in
simple terms. Thank you.

Venus
 
Venus said:
Hello,

I want to create a query that prompts the user to select a type of
work from a drop down list and then runs the query. So,

--Prompt the user "Select a Type" from the following list:
---HVAC
UTILITES
ELECTRICAL
COMMUNICATIONS
VEHICLE MAINTENANCE
--User Selects "HVAC"
--QUERY creates a spreadsheet of all HVAC work types

Any help that you can give would be great. I'm novice. . .please
explain in simple terms. Thank you.

Venus

You cannot use the automatic prompting for a parameter mechanism for this. That
requires an entry from the keyboard. What you should do is create a form with a
ComboBox displaying the choices. The user opens the form, makes their choice,
and then you have a button that runs the query or form/report that uses the
query.

Your query needs to be set up to reference the form for its criteria. To do
that use a criteria entry similar to...

Forms!NameOfForm!NameOfComboBox.
 
Rick,
This string is helpful to me, but I was not able to get my attempt to
work. My criteria is:
[Forms]![frmqrytest]![cbotype]
where cbotype is the dropdown that I chose my criteria from. The
dropdown works.
However, the query results are empty regardless of which option I chose
in the combobox.
This is the wizard-generatoed on-click event that my command button is
using:

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
stDocName = "qryDirectorate"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub

Am I doing something wrong? - obviously.
 
papa said:
Rick,
This string is helpful to me, but I was not able to get my attempt to
work. My criteria is:
[Forms]![frmqrytest]![cbotype]
where cbotype is the dropdown that I chose my criteria from. The
dropdown works.
However, the query results are empty regardless of which option I
chose in the combobox.
This is the wizard-generatoed on-click event that my command button is
using:

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click
Dim stDocName As String
stDocName = "qryDirectorate"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Exit_Command4_Click:
Exit Sub
Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click
End Sub

Am I doing something wrong? - obviously.

Does your ComboBox have more than one column (Display one while holding the
value of another)? In that case the value you SEE might not be the value that
the ComboBox actually contains. After amking your selection you can open the
immediate VBA code window and type...

?[Forms]![frmqrytest]![cbotype] <enter>

....and you should get back the value currently held in the ComboBox. See if it
is what you are expecting.
 
That is exactly what is happening.
Thanks, I was able to restructure my rowsource and get it to work.
Thanks for getting me going!
 
Back
Top