Steve Schapel
steve at datamanagementsolutions.biz
Wed Feb 12 02:26:20 CST 2014
Hi Chester
What is the value of the first (all wells) item in the combobox? Would it
work for you to just set that as the Default Value of the combobox, rather
than using that Form_Open code? And would it work for you to just use that
to determine the report? If I understand you correctly, I would not myself
favour using the Click event of the combobox to run the report anyway.
Maybe a little button on the form, to run the report? That way, the 'all
wells' option is the default, otherwise the user selects another item from
the combobox. And your code on the Click event of the command button along
the lines of:
Private Sub YourButton_Click()
If Me.WellNumber = "all wells" Then ' (or whatever the value of
the combobox)
DoCmd.OpenReport "rpt Set Down All"
Else
DoCmd.OpenReport "rpt Set Down in a Time Interval"
End If
End Sub
Regards
Steve
-----Original Message-----
From: Kaup, Chester
Sent: Wednesday, February 12, 2014 3:20 AM
To: Access Developers discussion and problem solving
Subject: [AccessD] Combo Box Question
I have a form with two text boxes and a combo box. I use the following code
to display a value in the combo box when the form opens. The code then
shifts the focus to the first text box. I have code attached to the combo.
It runs fine if I select something from the drop down list but does not run
if I click on the default value that is displayed in the combo box. If I
select another item in the drop down list and then go back and select the
default value displayed the code then runs. I think the problem has to do
with selecting something from the combo box list but I am unsure how to
proceed. Thanks.
Form opening code
Private Sub Form_Open(Cancel As Integer)
Me.WellNumber.SetFocus
Me.WellNumber.ListIndex = 0
Me.StartDate.SetFocus
End Sub
Combo box code
Private Sub WellNumber_Click()
Dim frm As Form, ctl As Control
Dim varItm As Variant, X As Variant
Set frm = [Forms]![frm Set Down Report Options]
Set ctl = frm!WellNumber
DoCmd.SetWarnings Off
'get the row number of the selected row in the list box
varItm = ctl.ListIndex
Select Case varItm
Case 0 'all wells
DoCmd.OpenReport "rpt Set Down All", acViewReport
Case Else
DoCmd.OpenReport "rpt Set Down in a Time Interval",
acViewReport
End Select
'Stop
End Sub