Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

print contents of db grid

Status
Not open for further replies.

neoice

Programmer
Feb 15, 2003
110
GB
Hello,

I want to print the contents of my db grid. can somebody show me how to do this please. the user will click on a command button which in turn should print the contents of dbgrid.

thanks in advance

neil
 
The easiest way is to use the me.printform command to print the whole vb form. Ohterwise, you could create a printable form, white background, and only the grid, and transfer the data into this. This is by far the easiest way I've found, without using much code.

BB
 
Thanks for your help. i did already try this but it is not practical as I have more data than can fit on a screen.

The data is held in an access table. is it posible to dump the data into a word document. I managed to mailmerge it, however it worked out that each record would have a seperate page. Ideally I would want it one after another.

Any ideas?

Thanks in advance

neil
 
You can create an Access report in the same database where your table is, setting the recordsource on the fly to match what's in your dbgrid.
Then you can print that report from within your VB app by using code similar to this:
(Be sure to add a reference to the Access Object Library - this example works with 9.0 Access 2000)

This has worked for me, but there may be better ways to do it -sorry just the basics here; no error-checking. On the 'OpenReport' method, you can include a filter or where clause, etc.

Dim appAccess As Object
Set appAccess = CreateObject("Access.Application")

appAccess.OpenCurrentDatabase ("path to your mdb file")
appAccess.DoCmd.OpenReport "your_reportname", acNormal (or acPreview)

appAccess.Application.Quit

Set appAccess = Nothing

Hope this helps,

Don
 
Create a VB DataReport and set it's Datasource to that of the Datagrid's recordset
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top