Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open report from ListBox on form

Status
Not open for further replies.

klmack

Technical User
Nov 18, 2002
17
0
0
US
Hi, this is a real beginner question...I know some SQL but not Visual Basic.

Have a form frmReport with listbox lstReport, tried adding command button with wizard to open report, how do I tell the command button to "open report selected in lstReport"? The other databases I'm trying to learn from either have the button call [Event Procedure] and I wind up baffled in Visual Basic, or the button runs a macro like Open Report: [Forms]![frmReport]![lstReport] which I can't get to work either.

If there isn't a real beginner answer to this, I'm just going to build an Open command button for each report on the form..

Thanks for any tips you might have!
Kerry
 
Have a look at the 4th argument of the doCmd.OpenReport method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi,

Looked at the doCmd.OpenReport in the one database, but up front they called a control for lstReport (the report box) and named a string CONACTION. I tried editing my button with the doCmd.Open Report arguments and it didn't recognize the keywords. I think I am missing a control on the form, the ctllstReport they reference. I guess I'll go back to the button for each report idea, there's only 10 reports so that's not too bad!

Here's the front of the code I was trying to copy:
Option Compare Database
Option Explicit

Dim ctltabReport As Control

Dim pgeMain As Page
Dim pgeBatch As Page
Dim pgeFilter As Page

Dim ctlcmdNew As Control
Dim ctlcmdDelete As Control
Dim ctlcmdPrint As Control
Dim ctlcmdPreview As Control

'Main page
Dim ctllstReport As Control
Dim ctllstGroup As Control
Dim ctltxtFrom As Control
Dim ctltxtTo As Control
Dim ctlcboproperty As Control
Dim ctltxtDateName As Control
Dim ctltxtDescription As Control

'Batch page
Dim ctllstBatch As Control
Dim ctllstAvailable As Control
Dim ctlcboName As Control

'Filter page
Dim ctllstProperty As Control
Dim ctllstAsset As Control
Dim ctllstLabor As Control

Private Function DoReports(CONACTION As String)

On Error GoTo DoReports_err

Dim varitem As Variant
Dim intI As Integer
Dim strFilter As String

If ctltabReport.Value = 1 Or ctltabReport.Value = 2 Then
MsgBox "Select the Reports tab or the Batch tab to print or print preview.", vbInformation, "Message"
Exit Function
End If

'page Main
If ctltabReport.Value = 0 Then
If ctllstReport.ItemsSelected.count = 0 Then
MsgBox "Select a Report.", vbInformation, "Message"
Exit Function
End If

DoCmd.Echo False, "Opening reports"
With ctllstReport
For Each varitem In .ItemsSelected
strFilter = .Column(5, varitem)

'check if date range is required
If IsNull(ctltxtTo) Or IsNull(ctltxtFrom) Then
If .Column(3, varitem) = -1 Then
MsgBox "Report requires a date range.", vbInformation, "Message"
DoCmd.Echo True
Exit Function
End If
End If

Select Case strFilter
Case "Property"
If IsNull(ctllstProperty) = False Then
DoCmd.OpenReport .Column(0, varitem), CONACTION, , "[Property]= " & FFFixQuotes(Forms!frmReport!lstProperty)
Else
DoCmd.OpenReport .Column(0, varitem), CONACTION
End If
Case "Asset"
If IsNull(ctllstAsset) = False Then
DoCmd.OpenReport .Column(0, varitem), CONACTION, , "[Asset]= " & FFFixQuotes(Forms!frmReport!lstAsset) & "And" & "[property]= " & FFFixQuotes(Forms!frmReport!lstProperty)
Else
DoCmd.OpenReport .Column(0, varitem), CONACTION
End If
Case "Labor"
If IsNull(ctllstLabor) = False Then
DoCmd.OpenReport .Column(0, varitem), CONACTION, , "[Labor]= " & FFFixQuotes(Forms!frmReport!lstLabor)
Else
DoCmd.OpenReport .Column(0, varitem), CONACTION
End If
Case Else
 
This is an example of very simple code you can copy and paste - the command button should have something like the following in the 'On Click' properties:

Private Sub Run_Report_Click()
On Error GoTo Err_Run_Report_Click

Dim stDocName As String

stDocName = Me.lstReport
DoCmd.OpenReport stDocName, acPreview

Exit_Run_Report_Click:
Exit Sub

Err_Run_Report_Click:
MsgBox Err.description
Resume Exit_Run_Report_Click

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top