If you can put the fields in question into a report, the printing is fairly
simple. You will need to add a reference to Interop.Access (Microsoft
Access 9.0 Object Library) and possibly Interop.Microsoft.Office.Core
(Microsoft Office 10.0 Object Library). The versions may vary depending on
what you have installed. This function will print any report saved in the
access database, with any where clause. The limitation is you have to
define the report ahead of time and cannot select the fields on the fly.
There is another option for printing a list of fields, although it is rather
indirect. Create a datagrid and populate it with the query you want.
Select all the rows in the datagrid and copy and paste them into Excel.
This can be done manually if you want the user to have to highlight and
copy/paste. You can also just select the query into excel if you want to
put the code together... Somewhere in this newsgroup is an example of
pupulating an excel spreadsheet with a query, you will find it posted as
"Error Exporting to Excel". I wold post the link but I havent figured out
how to link to a newsgroup yet.
Public Shared Sub PrintReport(ByVal strReportName As String, ByVal
strWhereClause As String)
'************************************************* **********************
' Public method
' opens access database and prints reports
'************************************************* **********************
'set the cursor to show we are working
Windows.Forms.Cursor.Current = Cursors.WaitCursor
Dim strDBPath = "C:\temp\MyAccessDatabase.mdb"
Dim oAccess As Access.Application
' Start a new instance of Access for Automation:
oAccess = New Access.ApplicationClass
' Open a database, not in exclusive mode:
oAccess.OpenCurrentDatabase(filepath:=strDBPath, Exclusive:=False)
' Print a report named Sales:
oAccess.DoCmd.OpenReport(ReportName:=strReportName ,
View:=Access.AcView.acViewNormal, WhereCondition:=strWhereClause)
oAccess.CloseCurrentDatabase()
'set the cursor to nomral when done
Windows.Forms.Cursor.Current = Cursors.Default
MsgBox("Report sent to printer.")
End Sub
"Lars Netzel" <ui****@adf.se> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Is it hard to make a Print button from a Windows Form that will print a
number of fields from an Access database in a fairly formatted way? How
does this work with the Print Dialoges and stuff?
I do NOT want to involve Crystal Reports! Been there and never want to do
it again. :)
/Lars