PDA

View Full Version : COM Printing VBA



smallt
07-07-2015, 11:04 AM
I have a code that prints to a text file:

Dim fn As String
Dim strSQL As String
Dim db As DAO.Database
Dim rs As DAO.Recordset

Set db = CurrentDb()

strSQL = "SELECT orderID,qty, product, price, time, staff from sales_cash "
Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)

fn = "c:\users\ted\desktop\MRA PRINTER\receipt.txt"
Open fn For Output As #1
Write #1, rs!time
Write #1, rs!staff
Write #1, "Welcome"

rs.MoveFirst
Do While Not rs.EOF
Write #1, rs!qty, rs!product, rs!price
rs.MoveNext
Loop

Write #1, line

Write #1, "TAXABLE 16.5% :", subtotal
Write #1, "VAT 16.5% :", tax
Write #1, "TOTAL VAT :", tax
Write #1, line

Write #1, "DATE :", date, "TIME:"; time
Write #1, line

Write #1, "TOTAL : ", subtotal
Write #1, "CASH : ", paid
Write #1, "CHANGE : ", change
Write #1, line

Close #1

Dim strPrtCmd As String


strPrtCmd = Environ("WINDIR") & "\system32\NOTEPAD.EXE /p " _
& strPath & strFileName & ".txt"
Shell strPrtCmd



Exit_write_file_Click:
' Exit Sub


this works pretty well, now what i need is to copy the same text file i just created and send to a DATECS FP700 Printer which is using COM2, BaudRate: 115200.

Alternatively, i can provide a code which works in VB (Not done by me) but i would like to use it in VBA; if you could help.

jonh
07-07-2015, 01:47 PM
VB6 code will probably work in VBA as is.