Solved

Printing an access database from visual basic

Posted on 1999-01-11
6
164 Views
Last Modified: 2013-11-25
I would like to print a tabel from my access database in visual basic. I really don't no how to do it so please help.
0
Comment
Question by:kgermann
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:jjbyers
ID: 1455371
Do you just want a dump to the printer or formatting?

You might want to start with the printer object.

Hope this helps.
0
 
LVL 6

Accepted Solution

by:
clifABB earned 100 total points
ID: 1455372
Here is the easiest way, assuming that you just want to print the total contents of a table:

Add a reference to Access to your project.  Select Project/References menu, select MS Access from the list.

Add the following code
(change Data.mdb to your Access file name, change Table to your table name)
  Dim accApp As New Access.Application
 
  accApp.OpenCurrentDatabase "Data.mdb"
  accApp.DoCmd.OpenTable "Table"
  accApp.DoCmd.PrintOut acPrintAll

0
 
LVL 6

Expert Comment

by:clifABB
ID: 1455373
The other way to do this is as follows:
(You'll need to make sure there is a reference to the data objects)

  Dim dbData  As Database
  Dim rsTable As Recordset
  Dim nCnt1   As Integer
 
  Set dbData = OpenDatabase("c:\mds\data\MDSTables.mdb")
  Set rsTable = dbData.OpenRecordset("Paste Errors")
  For nCnt1 = 0 To rsTable.Fields.Count - 1
    Printer.Print rsTable.Fields(nCnt1).Name; vbTab;
  Next nCnt1
  Printer.Print
  Do Until rsTable.EOF
    For nCnt1 = 0 To rsTable.Fields.Count - 1
      Printer.Print rsTable.Fields(nCnt1); vbTab;
    Next nCnt1
    Printer.Print
    rsTable.MoveNext
  Loop
  Printer.EndDoc

0
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.

 

Author Comment

by:kgermann
ID: 1455374
The code is working fine, but it is only the text from the tabel I am getting. I would like the linies also.

thanks for your help
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1455375
I'm not sure what you mean by "linies".  Can you explain?
0
 

Author Comment

by:kgermann
ID: 1455376
What I mean is that, I would like to see the printing as a tabel they way I do it in access. I hope you understand.

Kasper Germann
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 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