Opening a report from a list box

Starman

Captain Noble
Local time
Today, 16:41
Joined
Jan 25, 2007
Messages
45
I have a list box that displays the names of reports that can be printed. The list box is populated from a table with three columns - an autonumber, the name of the report, and a description. I hide the first two, displaying the third. I want the user to be able to double-click the report they want and have it come up, but I'm having trouble with the code. This is what it looks like:

Private Sub lstReport_DblClick(Cancel As Integer)
On Error GoTo Err_lstReport_DblClick

Dim stRptName As String

stRptName = "'" & Me.lstReport.Column(1) & "'"

If Me.lstReport.Column(1) = "" Then
Exit Sub​
End If

DoCmd.OpenReport stRptName, acViewPreview​

Exit_lstReport_DblClick:
Exit Sub​

Err_lstReport_DblClick:
MsgBox Err.Description
Resume Exit_lstReport_DblClick​

End Sub

The error message I get is that the report name is misspelled or doesn't exist. I've triple-checked the spelling of all of the reports and they are all correct, but no matter which report I try to open I get the error message.

Any ideas?
 
Just change this:
stRptName = "'" & Me.lstReport.Column(1) & "'"

to this:
stRptName = Me.lstReport.Column(1)
 
Gawd, I feel like an idiot. Thanks for your help.
 

Users who are viewing this thread

Back
Top Bottom