Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to send one line to printer or report using VBA

Status
Not open for further replies.

sklambert

Programmer
Sep 15, 2003
31
US
I need help with printing. I am writing a procedure to read and update records in a table. I want to read a record, print the value of a field, change the value of the field, then print the value of the field again. I want to also add comments with the values. I want to send each line to the printer as the code is executed. Alternatively, I need to know how to send each line to a report, then print the report at the end of code execution.

So I want to do this in code:

With rst
.MoveFirst
Do While Not .EOF
.Edit
Send "VEHICLE NUMBER " & the value of rst![VEHICLE NUMBER] to printer
Change the value of rst![VEHICLE NUMBER]
Send "CHANGED TO " & the new value of rst![VEHICLE NUMBER] to printer
.Update
.MoveNext
Loop
End With

Please, any help would be greatly appreciated!!! Thanks in advance!!!
 
If your printer is connected to your parallel port, simply send the data to port LPT1. I'm not very competent with VBA, but in a batch script this would look something like:

ECHO The data is as follows: %DataStoredInThisVariable%>>LPT1
 
Hi,
even if you successfully send these lines to the printer, I reckon it would probably print each on a different page. Perhaps you could build a table called tblAudit with fields
[OldVehicleNum] and [NewVehicleNum].
In your code, declare rsAudit as a recordset:

declare sOldValue as string, sNewValue as string
declare rsAudit as recordset

docmd.runsql "Delete * from tblAudit" 'Clear the audit table
set rsAudit=db.openrecordset("tblAudit")
With rst
.MoveFirst
Do While Not .EOF
.Edit
sOldValue=rst![VEHICLE NUMBER]
Change the value of rst![VEHICLE NUMBER]
sNewValue=rst![VEHICLE NUMBER]
.Update
rsAudit.Addnew
rsAudit![OldVehicleNum]=sOldValue
rsAudit![NewVehicleNum]=sNewValue
rsAudit.Update
.MoveNext
Loop
End With
docmd.openreport "rptAudit"

where "rptAudit" is a report printing each line of the table tblAudit

 
Thanks for your input. I really appreciate it. SarahG, I don't think I can use the code you supplied, but you gave me an idea to work with. I will continue to try to develop this. Again, much appreciated.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top