Printer Object + TextBox Control will do.
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:
Code:
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