Solved

Printing reports which are stored in Access

Posted on 2003-11-11
6
446 Views
Last Modified: 2010-04-17
What is the code to print reports, which are stored in Access, from VB? Thanks
0
Comment
Question by:matt_fennell
  • 3
  • 3
6 Comments
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 25 total points
ID: 9721758
This way:

Const dbPathName = "c:\database.mdb"
Const strPassword = "PASSWORD"
Dim Acc As Object, db As Object

Set Acc = CreateObject("Access.Application")
Set db = Acc.Application.DBEngine.Workspaces(0).OpenDatabase(dbPathName, 0, False, ";pwd=" & strPassword)
Acc.OpenCurrentDatabase dbPathName, False
Set db = Nothing
Acc.DoCmd.OpenReport "ReportName", acPreview
Set Acc = Nothing
0
 

Author Comment

by:matt_fennell
ID: 9722281
This piece of code seems to try and install Access. Would it be simpler if I just used a datacontrol with the recordsource being the report in question?
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 9722320
If you want to print reports that are into an Access database, you need to have Access already installed onto your PC. The DataControl can only read the data from the Access database.
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:matt_fennell
ID: 9722435
Access is already installed. And I have my tables, queries, reports etc saved and linked to my VB program. But for some reason that code you have given me attempts to install Access when it is already installed.

Other than of course "report name" which I changed to the report name in my Access db, what other info needs to be changed from your code? You'll have to forgive my incompetence, I am only a beginner - novice programmer.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 9722791
>>And I have my tables, queries, reports etc saved and linked to my VB program

Reports cannot be "linked" to a VB program. A VB program using DAO/ADO/RDO can only use tables and queries.

>> attempts to install Access when it is already installed

Insert your CD and let it go. It may install a feature that wasn't installed initially.
0
 

Author Comment

by:matt_fennell
ID: 9723375
Thank you. Reports are printing.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now