Open associated report based on selection in combo box

  • Thread starter Thread starter Jonathan Brown
  • Start date Start date
J

Jonathan Brown

I would like to have a form that has nothing more than a
combo box and an "open" button. I want the combo box to
list all of the reports that I've created.

All I want to do is select the report I'd like to view and
then click the "open" button to preview it.

It would be nice if in the future if I create new reports,
it would automatically appear in the combo box.
 
so easy!

'http://access911.net
'1:create a form
'2:insert a combo box
'3:insert a command button
'4:copy these vba code into form module

Private Sub Command2_Click()
If IsNull(Combo0.Value) = False Then
DoCmd.OpenReport Combo0.Value, acViewPreview
End If
End Sub

Private Sub Form_Open(Cancel As Integer)
Dim i As Object
Dim strValue As String
For Each i In Application.CurrentProject.AllReports
strValue = i.Name & ";" & strValue
Next
Me.Combo0.RowSourceType = "Value List"
Me.Combo0.RowSource = strValue
End Sub
 
Add combo and command button to a form (let's call them cboReportList and
cmdOpenReport).

'Set this SQL as the rowsource for cboReportList...
SELECT Name
FROM MSysObjects
WHERE Type = -32764

'Paste this sub into your form module
Private Sub OpenReport
On Error GoTo Err_OpenReport

If Not IsNull(Me.cboReportList) Then
DoCmd.OpenReport Me.cboReportList, acViewPreview
Else MsgBox "Please select a report from the list!", vbExclamation, "No
report selected"
End If

Exit_OpenReport:
Exit Sub

Err_OpenReport
MsgBox Err.Number & ": " & Err.Description
Exit Sub

End Sub

In the AfterUpdate event of your combo type: OpenReport (this will call the
procedure you just created)
Put the same call in the Click event of the button cmdOpenReport
 
Back
Top