Solved

Printing an access database from visual basic

Posted on 1999-01-11
6
165 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

867 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

18 Experts available now in Live!

Get 1:1 Help Now