By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

Open report from VBA, without printing

P: 5
Hi!

I have experienced a a really odd problem when writing an Access application. I would programatically open a report (because i need to pass a value to it) with DoCmd.OpenReport. I would like to open it for viewing, not in print preview (as there the recordsource couldn't be modified anymore), like when you open it from the command bar with the button "Report View".
The odd thing is, that apparently there's no way to simply view the report without immediately printing it :-). I tried the code
DoCmd.OpenReport "ReportName", acViewReport, , , acWindowNormal, "value_to_pass"
with every view mode. As i know with acViewReport it has to display the report instead of printing it... Is this some bug or i am missing something?:
Sep 14 '07 #1
Share this Question
Share on Google+
5 Replies


nico5038
Expert 2.5K+
P: 3,072
Use the Preview like:

DoCmd.OpenReport "ReportName", acViewPreview, , , , "OpenArgs"

Nic;o)
Sep 14 '07 #2

P: 5
Use the Preview like:

DoCmd.OpenReport "ReportName", acViewPreview, , , , "OpenArgs"

Nic;o)
Thanks, that would do it, but as i have written, unfortunately it's not possible to modfiy the recordsource prooperty in print preview, so it's not possible either to make a report with a customized query.
I made a new try and have explored that with an open argument (even with an empty one) Access 2007 doesn't print. That's OK, but Access 2003 still does...
Sep 14 '07 #3

nico5038
Expert 2.5K+
P: 3,072
When I want a "dynamic" recordset I just manipulate the query before activating the report.
In general however using a filter gives enough flexibility, but incase you really need the query to change use this code before the Docmd.OpenReport:

Expand|Select|Wrap|Line Numbers
  1. Dim qd as DAO.Querydef
  2.  
  3. set qd = currentdb.querydefs("qryRptYours")
  4. qd.SQL = "select x from tblY where x =" & Me.X
  5.  
Getting the idea ?

Nic;o)
Sep 15 '07 #4

ADezii
Expert 5K+
P: 8,638
Thanks, that would do it, but as i have written, unfortunately it's not possible to modfiy the recordsource prooperty in print preview, so it's not possible either to make a report with a customized query.
I made a new try and have explored that with an open argument (even with an empty one) Access 2007 doesn't print. That's OK, but Access 2003 still does...
If you wish to make any modifications to a Report prior to actually Opening/Previewing it, open the Report Hidden first, make your changes, then Re-Open in the proper Mode.
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "rptEmployee", acViewNormal, , , acHidden
Sep 15 '07 #5

P: 5
Thanks a lot to both of you, it works!
Sep 15 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.