View Full Version : print or show my report


smiler44
02-12-2010, 11:09 PM
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"




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

smiler44
02-13-2010, 08:18 AM
I am after some help with printing only certain columns of a table from an access database. I think I need to do this via code, visual basic code as I'm using visual basic but am not doing very well. i need to print on A4 paper and would like the column headers on each page and as a footer page x of ?

Can you give me advice (code) to print the table anlong with the column headers and grid lines?

Thank you
smiler44

Rabbie
02-13-2010, 08:46 AM
As you only want to print certain columns just write a report to display the columns you want to show.

smiler44
02-13-2010, 01:32 PM
if I knew how to write the code I would have done so and not posted here for help. The reason for my post is that I dont know what the code should be?
smiler44

pbaldy
02-13-2010, 01:51 PM
There would likely be no code required. Try starting with the report wizard and customize as desired in design view.

smiler44
02-13-2010, 11:45 PM
I have no experience of crystal reports.

Using the Report Desinger in visual basic v5 I think I have created a report. I think this is quite an old version of crystal reports
Using visual basic how do I either display the report on my screen or print it. I can see in the desinger that there is an opton to send it to screen or printer but can not work out what "code" i need to use to actually make the report appear

thnak you

smiler44

smiler44
02-14-2010, 12:31 AM
search on google and some playing around and I have made a major leap forward.

place a crystal report control on the form, set the report file name property to c:\directoryname\reportname.rpt. place the code below to a command button. this sends it to the printer


R1.DiscardSavedData = True
CR1.WindowState = crptMaximized
CR1.ReportFileName = "c:\directoryname\reportname.rpt"
CR1.PrintReport


smiler44

smiler44
02-14-2010, 12:35 AM
Thank you Paul, although your reply was for me a bit vague and I was not sure where to find the report wizard I did find it and create a report, played around with it... still some playing to do and then found via a google search how to send the report to the printer via a button on my form.

Thanks again Paul

smiler44:)

smiler44
02-14-2010, 12:38 AM
although I'd like to know how to amend the posted code to do what I want i have with help from the crystal reports forum been put on the right path and then searching google found the code to print my report with gridlines

smiler44