I am using a report to print name badges on demand. I have a timer that checks for the appearance of a record in a database table which then starts a thread for the printing when one or more records are available.
The problem is that the report (name badge) does not print unless the application is closed or the report is run again. In second situation, the first name tag prints but the second one does not. The code for the report in the thread is below. Any suggestions about what I’m missing would be appreciated.
//if we are here then there are one or more badges to print
// and the printer setup is completed
var rs as RowSet
rs=app.SettingsDB.SelectSQL("SELECT * FROM BADGES WHERE QR='' ")
//Add a QR code and do some formatting for all if the current rows
While not rs.AfterLastRow
Var p As Picture = Barcode.Image(rs.Column("IMISID").StringValue, 120, 120, Barcode.Types.QR)
rs.EditRow
rs.Column("QR").BlobValue=p.ToData(Picture.Formats.PNG)
rs.Column("LAST").Value=rs.Column("LAST").StringValue.Uppercase
rs.Column("CITY").Value=rs.Column("CITY").StringValue+", "+rs.Column("STATE").StringValue+" "+rs.Column("COUNTRY").StringValue
rs.SaveRow
rs.MoveToNextRow
wend
//get only badge records that have the QR inserted in case another badge was added after the previous select
rs=app.SettingsDB.SelectSQL("SELECT * FROM BADGES WHERE QR > '' ")
//Format the report fields and print
If g <> Nil Then
Var rpt As New Badge
rpt.FirstName.TextSize=30
rpt.FirstName.TextFont="Palatino Linotype"
rpt.LastName.TextSize=30
rpt.LastName.TextFont="Palatino Linotype"
rpt.Location.TextSize=30
rpt.Location.TextFont="Palatino Linotype"
rpt.FirstName.Bold=true
rpt.LastName.Bold=true
rpt.Location.Bold=True
// if the report runs successfully, print it
If rpt.Run(rs, printerSetup) Then
rpt.Document.Print(g)
rpt.Close
me.AddUserInterfaceUpdate("UIMessage" : "Badge printed")
//all done with these badges---remove the badge records
app.SettingsDB.ExecuteSQL("DELETE FROM BADGES WHERE QR > '' ")
else
me.AddUserInterfaceUpdate("UIMessage" : "Badge print fail")
End If
End If
//reset the flag to allow the timer to run the thread again
Printing=false
Best regards,
Rich