View Full Version : Combo Box to Print/Preview Reports


LisaP
01-12-2001, 03:09 AM
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?

ntp
01-12-2001, 04:06 AM
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

LisaP
01-12-2001, 04:55 AM
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?

RpbertS
01-12-2001, 09:08 AM
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