Open Query/Form/Report in a particular view from a form without creating event procedures or macros

A

auke

Hi,

I want to create something similar to a switchboard, but then also for
queries. Therefor I'm creating a form with a few pushbuttons. When I
have a put a pushbutton on the form, I cancel the pushbutton-wizard
(the solution to my problem is also in this wizard, but that generates
lots of code) and then I go to the properties of the push button.

Under the tab "events" I can place the following code in the OnClick
event:
=docmd.openreport("Reportname")
This works!

However, the report is then automatically printed. To circumvent this,
I want to open the report in the "print preview" mode. However the
following codes don't work:
=docmd.openreport("Reportname";"acViewPreview")
=docmd.openreport("Reportname;acViewPreview")
docmd.openreport "Reportname"; acViewPreview
In the last case, Access notifies that there is no macro called docmd
(that's fair).

Finally, my question: Is there a way to open a report/query/form in a
other view mode than the default view mode without creating an event
procedure or a macro?

Thanks in advance!

Ps. I've got Access 2000 and the localisation is Dutch (hence the ;
instead of the , ).
 
G

Guest

no. you have to have something to trigger the report,
here is a line i use as an on click button event.
private sub printrpt()
DoCmd.OpenReport "DeadStockWIP",acViewPreview
end sub
 
B

Brendan Reynolds

I believe you'll need to use the literal numerical value for the view-type
argument, rather than the name of the constant, e.g. 2 instead of
acViewPreview.

Use of DoCmd in expressions is blocked in 'sandbox' mode, but you can work
around that by wrapping the call to DoCmd.OpenReport in a public function
and using the public function in your expression ...

Public Function MyOpenReport(ReportName As String, ViewMode As AcView)

DoCmd.OpenReport ReportName, ViewMode

End Function

=MyOpenReport("rptTest",2)

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top