473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to open report directly from Access db?

How to open report directly in Access 2010 when we open the file?

Under options - Current Database, I see Display Form.

Do I need to write a VBA code for this and if so, which event.

I also want this to open in print preview mode instead of Report.

TIA
SFL
Feb 15 '13 #1

✓ answered by Seth Schrock

The OnOpen event of the report only runs when the report gets opened so you can't very well tell the report to open when it is already being opened.

What you will need to do is create a blank form. Put the code to open the report in the form's OnOpen event and then set Cancel = True. This will close the form after the report is opened. You then need to go to File>Options>Current Database and then in the Display Form drop down box, select the name of the form that you just created. This will make it so that when you open the database, the form will start to open, this will trigger the form's OnOpen event and open the report. The form will then close leaving you with just the report. The user won't even see that the form was opened.

8 4302
Seth Schrock
2,965 Expert 2GB
The code to open the report is
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport "report name", acViewPreview
The event depends on how you want to open it. If you have a button that you want to click to open the report, then you would put this in the button's OnClick event. I would say that this is probably the most common method, but you can put it in any event that you want as long as you know what triggers the event and you want the report to open every time the event is triggered.
Feb 15 '13 #2
I also noticed that the default view in my report property was set to Report, I changed it to Print Preview and now when I open the report, it opens in print preview.

But my issue is little different.
In my access db, I have couple of tables and one report, no form.

So I want my report to open directly when we double click the access db file, so user dont have to go an extra step of opening and db file and then clicking the report.

I tried to put your code in open event of report but that did not help.
Feb 15 '13 #3
Seth Schrock
2,965 Expert 2GB
The OnOpen event of the report only runs when the report gets opened so you can't very well tell the report to open when it is already being opened.

What you will need to do is create a blank form. Put the code to open the report in the form's OnOpen event and then set Cancel = True. This will close the form after the report is opened. You then need to go to File>Options>Current Database and then in the Display Form drop down box, select the name of the form that you just created. This will make it so that when you open the database, the form will start to open, this will trigger the form's OnOpen event and open the report. The form will then close leaving you with just the report. The user won't even see that the form was opened.
Feb 15 '13 #4
Blank form created and inserted following code
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Load()
  2. DoCmd.OpenReport "WFA Testing Status Report", acViewPreview
  3. Cancel = True
  4. End Sub
With the above code, focus is on the Form and it stays open.
Feb 15 '13 #5
Seth Schrock
2,965 Expert 2GB
Try instead of the Cancel = True try DoCmd.Close acForm, "your blank form name"
Feb 15 '13 #6
NeoPa
32,556 Expert Mod 16PB
The first approach is far preferable. The only problem there is trying to use the Form_Load() event procedure instead of the Form_Open(Cancel As Integer) event procedure, which you will probably see quite easily, is actually designed to allow cancelling, whereas Form_Load() is not.

PS. I'm afraid I must reset Best Answer here as it is not the sort of information we want to propagate.
PPS. Seth, if you'd like to update post #4 to correct this confusion then I'll happily set it as Best Answer. To get my attention drop a post in at the end and I'll delete that when I see it.
Feb 15 '13 #7
zmbd
5,501 Expert Mod 4TB
There is an alternative.
You do not need the form in the open event


In V2010 you still have the "AUTOEXEC" macro available.

This is one of the few times I use the macro language.

Ribbon:Create:Macros & Code
Select the Scroll Icon Labeled "Macro"
When the macro editor opens
Click the dropdown arrow
Scroll down to the: OpenReport
In the options block that appears in the window:
Report Name: your report
View: Print Preview
Filter name: blank
Where Condition: blank
Window Mode: Normal

Save the Macro as "AUTOEXEC"
Close the database, reopen the database, the report will now open.
Feb 17 '13 #8
NeoPa
32,556 Expert Mod 16PB
I know that a number of respected experts still use macros for just that reason. My own preference is still to avoid them. This can be done with forms and VBA, so why not do so. That's my thinking anyway. As I say, if you (or anyone) chooses the AutoExec appraoch they will certainly find themselves in good company.
Feb 17 '13 #9

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

Similar topics

3
by: MJ | last post by:
I have Access 2000. Isn't there an easy way to download a report directly from Access into Word without making an .rpt file first?
2
by: jpodesta | last post by:
I am working on a trade processing project for my company. I would like to export a report directly to .csv format. I have looked all over in the groups for a way to do this. Appearently something...
2
by: amith.srinivas | last post by:
Hi all, From a word macro in VBA, I am trying to create a report in access DB. The report is based on a query with a parameter. I am using Set rpt = Application.CreateReport rpt.RecordSource =...
0
by: moshe_n | last post by:
Hello I try to export report from access 2000 by mail and always i get the massege " the report can not open the mail application" I use the Lotus notes application , noach,
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
6
by: rewindspline | last post by:
hello, i have a simple MS Access 2003 database for producing reports from multiple tables. this morning i made a slight change to some text boxes in the report and now i can't open the report....
1
by: Saberthedream | last post by:
Hello, I am creating a crystal report in .net and i need to print the crystal report directly without showing it to user . for this i am writing code Report.PrintToPrinter(1, true, 0, 0); but...
4
by: Phil Stanton | last post by:
I am opening a report (in Preview) from a menu system I use the following code if there is no data in a report Private Sub Report_NoData(Cancel As Integer) MsgBox "There are no errors in...
4
by: pacarv | last post by:
I've created a database in Access 2003 with multiple reports that are accessable from the switchboard. The switchboard also has a print button. The user selects the report from the menu which then...
0
by: sarvmardan | last post by:
how to open a report in access containing filtered data using two combo boxes on form and a button to click. let i have two fields and other is . two comboboxes are combo11 and combo9. plz post...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.