Trying to use VBA to open a report - wouldn't work

in22

Registered User.
Local time
Today, 16:04
Joined
Aug 16, 2013
Messages
38
So when I open a database a main form appears (like a switchboard). I have buttons which take me to several other forms (for multiple uses). There's a form which has buttons that are supposed to open queries and reports. Herem I'm using the following code to open a report.

Private Sub cmdFullTimersR_Click()

DoCmd.SelectObject acReport, Me.Name
DoCmd.Minimize
DoCmd.OpenReport "Full Timer - Current Month", acViewNormal, , , acWindowNormal

End Sub

The form is named "Audit Tool Summary". However when I click the button the code errors out saying: 'The object 'Audit Tool Summary' isn't open.

I'm confused. I have used the same code to open queries (which open in a form) through buttons on the same form. There it works. But I don't understand why opening a report is a problem. A sample code for opening a form through the same process is below:

Private Sub cmdColl_Click()

DoCmd.SelectObject acForm, Me.Name
DoCmd.Minimize
DoCmd.OpenForm "Variable Coll - Current Month", acNormal, , , acFormReadOnly, acDialog

End Sub

Btw, I have designed the database such that there is just one form open at any point. When you click a button to open a form etc. the active window minimizes and the new window opens. I'm trying to keep the same trend going with reports...

Is there a different approach to opening reports? Please help :confused:
 
Might the difference here be relevant? ;)

DoCmd.SelectObject acForm, Me.Name
DoCmd.SelectObject acReport, Me.Name
 
I didn't understand your post :o
 
How about this:

DoCmd.SelectObject acForm, Me.Name
DoCmd.SelectObject acReport, Me.Name

Are you selecting a form or a report to minimize?
 
Oh! Gotcha! I had to minimize the form :)

But here's another problem. Instead of opening the report in print preview mode, the code somehow made it print the report. I got the dialog box suggesting "Printing report xyz to the printer..."

I just want to view the report in print preview...any ideas?
 
Sure, look at the arguments for OpenReport. The option acViewNormal is for printing.
 

Users who are viewing this thread

Back
Top Bottom