Am having a bit of trouble with this one!
I have created a form with a combo box [ComboReports] the row source is a table listing all report names. I have two command buttons [Print] and [Preview] and have created the following on_click event code:-
Private Sub Preview_Click()
On Error GoTo Err_Preview_Click
Dim stDocName As String
If Me![ComboReports] = "Engineer" Then stDocName = "RptEng"
If Me![ComboReports] = "Projects" Then stDocName = "RptProjects"
If Me![ComboReports] = "Group" Then stDocName = "RptGroup"
DoCmd.OpenReport stDocName, acViewPreview
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox "Select a Report!"
Resume Exit_Preview_Click
End Sub
The combo box works fine, it lists all the reports and i am able to select one, but when i click on [Preview] i just get the MsgBox even though i have selected a report?
Have double and triple checked the code and cant see what is wrong (but then i had a very late night last night!) Can anyone advise?
I have created a form with a combo box [ComboReports] the row source is a table listing all report names. I have two command buttons [Print] and [Preview] and have created the following on_click event code:-
Private Sub Preview_Click()
On Error GoTo Err_Preview_Click
Dim stDocName As String
If Me![ComboReports] = "Engineer" Then stDocName = "RptEng"
If Me![ComboReports] = "Projects" Then stDocName = "RptProjects"
If Me![ComboReports] = "Group" Then stDocName = "RptGroup"
DoCmd.OpenReport stDocName, acViewPreview
Exit_Preview_Click:
Exit Sub
Err_Preview_Click:
MsgBox "Select a Report!"
Resume Exit_Preview_Click
End Sub
The combo box works fine, it lists all the reports and i am able to select one, but when i click on [Preview] i just get the MsgBox even though i have selected a report?
Have double and triple checked the code and cant see what is wrong (but then i had a very late night last night!) Can anyone advise?