print access database table
I would like to print a table from an access database. The code below
I got from somewhere a number of years ago and amended it as best I could but it's not good enough. can you help?
currently the columns being printed are all merged in to one long word
how do I modify this to print :
column headers on each A4 page?
print the gridlines?
print centrally between grind lines?
have a footer saying Page 1 of what ever the last page is?
I have even tried recording a macro in excel hoping to be able to work to how to do it in vb but could not work out how to convert
"with activesheet.pagesetup"
thank you in advance
smiler44
I would like to print a table from an access database. The code below
I got from somewhere a number of years ago and amended it as best I could but it's not good enough. can you help?
currently the columns being printed are all merged in to one long word
how do I modify this to print :
column headers on each A4 page?
print the gridlines?
print centrally between grind lines?
have a footer saying Page 1 of what ever the last page is?
I have even tried recording a macro in excel hoping to be able to work to how to do it in vb but could not work out how to convert
"with activesheet.pagesetup"
Code:
Private Sub Cmdprint_Click()
' Use 1 inch margins.
Const TOP_MARGIN = 1440
Const LEFT_MARGIN = 1440
Dim bottom_margin As Single
Dim db As Database
Dim qdef As QueryDef
Dim rs As Recordset 'database is rs
Dim dbname As String
MousePointer = vbHourglass
DoEvents
' Open the database.
dbname = App.path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "Dbase.mdb"
Set db = OpenDatabase(dbname)
' Get the records.
Set qdef = db.CreateQueryDef("", " select * from tablename where TEST like'" + ("*") + "'order by TEST") 'prints
'only these coloumns
Set rs = qdef.OpenRecordset(dbOpenSnapshot)
' Read the data and print it.
bottom_margin = Printer.ScaleTop + Printer.ScaleHeight - 1440
rs.MoveFirst
Printer.CurrentY = TOP_MARGIN
Do While Not rs.EOF
' Use rs!FieldName to get the data for
' the field named FieldName.
Printer.CurrentX = LEFT_MARGIN
Printer.Print _
Format$(rs!make) & v; bTab & Format$(rs!colour) & v; bTab & Format$(rs!livery)
' See if we have filled the page.
If Printer.CurrentY >= bottom_margin Then
' Start a new page.
Printer.NewPage
Printer.CurrentY = TOP_MARGIN
End If
rs.MoveNext
Loop
rs.Close
db.Close
' Finish printing.
Printer.EndDoc
MousePointer = vbDefault
End Sub
thank you in advance
smiler44