PDA

Click to See Complete Forum and Search --> : How to print?


nigel_chong98
Jun 7th, 2000, 07:43 AM
Let say i have a lot of records like e.g

name age class sex
mary 10 pri 5 f
david 10 pri 5 m

what are the commands to get all these records printed out and how to align them to look professional. Do you know how to preview before print also?

Thank you for your help.

curlywink
Jun 8th, 2000, 06:08 AM
Hi there,

If you want to print eg.. records directly use the Printer object etc.. if u want it previewed, try using Crystal Reports (included w/ vb) ...


Hope this helps ...

Chris
Jun 8th, 2000, 04:42 PM
Hi nigel_chong88, all you need is...

1 TextBox control
1 CommandButton


need not necessary must use Crystal Report.

The code is just as simple as below:

Option Explicit
Private Db As DAO.Database
Private Rs As DAO.Recordset
Private Sub Command1_Click()
'Get the first printer from the system's printer list
Dim xPrinter As Printer
For Each xPrinter In Printers
If IsObject(xPrinter) Then
Set Printer = xPrinter
Exit For
End If
Next
Printer.Orientation = 1
'Print the preview data into selected printer
Printer.Print Text1
Set Printer = Nothing
End Sub

Private Sub Form_Load()
'Retrieve data from the Bibli.mdb on Authours Table
'There is total 3 fields from this Table
'1. Au_ID
'2. Author
'3. Year Born
Set Db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\Biblio.mdb", False, False)
Set Rs = Db.OpenRecordset("SELECT * FROM Authors WHERE Au_ID < 200;", dbOpenSnapshot)
While Not Rs.EOF
'Put all the records into the Text1 TextBox control for preview purpose.
'For alignment, I used vbTab over here to seperate each type of records.
'Note: For safty purpose, make sure you have set the TextBox Locked
'properties to True, else the user will be free to change
'the retrieved records.
Text1 = Text1 & Rs.Fields(0) & vbTab & Rs.Fields(1) & vbTab & Rs.Fields(2) & vbCrLf
Rs.MoveNext
Wend
Rs.Close
Db.Close
Set Rs = Nothing
Set Db = Nothing
End Sub

Negative0
Jun 8th, 2000, 11:04 PM
I agree with Chris, but you might not want to use vbTab if your strings are of varying lengths. You could try:

Text1 = Text1 & Rs.Fields(0) & space(20-len(rs.fields(0)) & Rs.Fields(1) & space(20-len(rs.fields(1)) & Rs.Fields(2) & vbCrLf

This will help keep things lined up.

This code works if you use a font like courier new.

Chris
Jun 9th, 2000, 02:03 AM
Hi! Negative0, how come I can forget about this... By the thanks for your amendment. :)