Combo Box & Command Button

G

Guest

I have a comand button that opens a form in print preview and has a filter
that asks a user to enter a location. How do I add a combo box to let the
user select the location instead of typing it in like a condition. Any helo
is help
 
D

Dirk Goldgar

PAM said:
I have a comand button that opens a form in print preview and has a
filter that asks a user to enter a location. How do I add a combo box
to let the user select the location instead of typing it in like a
condition. Any helo is help

From the sound of it, you're going to need to open another form that has
the combo box on it for choosing the location, as well as a command
button to open the final form filtered for the selected location. So
your current button opens this new, intermediate form, and the button on
that form opens the form you ultimately want to display.

That is, unless there's a place on the form that holds the current
command button, where you could put a combo box to choose the location.
Then you wouldn't need the intermediate form.
 
D

Dirk Goldgar

pam said:
I have a combo box, but I need the user to select a value in that
combo box which will then open a report with only the data from the
value the user selected in the combo box.

Is it a form or a report that you want to open? You said "form" before,
but "report" now. I'll assume it's a report.
I'll also assume that the combo box and the command button are on the
same form. I'll call the combo "cboLocation", the button "cmdReport",
and the report to be opened, "rptMyReport". I'll assume that the
Location field is a text field.

If you want to require that the user have chosen a location before
clicking the button to open the report, you could have code for the
button's Click event procedure like this:

'----- start of example code -----
Private Sub cmdReport_Click()

If IsNull(Me.cboLocation) Then
MsgBox "Please choose a location first!"
Else
DoCmd.OpenReport "rptMyReport", _
WhereCondition:="Location = '" & Me.cboLocation & "'"
End If

End Sub
'----- end of example code -----

Note: that also assumes that the Location field won't contain the
single-quote character (').
 
J

John Vinson

I have a comand button that opens a form in print preview and has a filter
that asks a user to enter a location. How do I add a combo box to let the
user select the location instead of typing it in like a condition. Any helo
is help

Put the combo box, unbound, *on the form* which has the button. Use a
criterion such as

=Forms![name-of-your-form]![name-of-your-combo]

btw, if you want to print the data, use a Report rather than a Form.
 

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