Combo Box to Print/Preview Reports

LisaP

Registered User.
Local time
Today, 22:48
Joined
Nov 13, 2000
Messages
27
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?
 
Could it be that when you click on the preview button, the combobox loses focus and the selected item is also lost? Just a thought.

What you can do is find out exactly what error is occuring. Include this as the message in your message box:


Msg = "Error # " & Str(Err.Number) & " was generated by "
& Err.Source & vbcrlf & Err.Description

You'll find out exactly what is causing your error and maybe able to debug the error.

ntp
 
ntp,

Thanks for the advise - the error description says that I am trying the openreport method without naming a report, so yes i think that the combo box is losing focus when i click on the preview command button.

Any ideas?
 
Hi,
I created a small dbase that shows you how I took care of the same problem your having if you or anyone is interested email me at Fdarouian@yahoo.com
 

Users who are viewing this thread

Back
Top Bottom