Report only prints on close or new report

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

Forgot to mention…XOJO 2024r3.1 & 2024r4 on Windows 11.

should your where part better is null or not is null because it is a binary field?

add a few System.DebugLog

have a look if SaveRow really commit the data to database direct.

reset the flag to allow the timer to run the thread again

maybe use the RunMode instead of a flag
.RunMode = Timer.RunModes.Off
.RunMode = Timer.RunModes.Multiple

your thread is cooperative?

I havent used reports in this way.But ordinary printing only 'happen’s when the graphics context goes out of scope.

Does this make a difference?

rpt.Document.Print(g)
rpt.Close
g = nil

( you would need to get another g for a second run)

1 Like

Thanks the suggestions…the null/not null would be correct if I allowed null but comparing to empty or not empty is working because I insert the record with a SQL empty string in the REST interface that takes the badge print request from an Android tablet.

I initially had the thread as preemptive but I have also tried it with cooperative. No difference.

Yes, the SaveRow really happens because I see the QR and other edits in the DB if I place a debug break.

The timer has to continue to run because it monitors several other conditions like connection to a remote database and a REST interface. The flag is used to make sure the timer does not call the thread again until the thread completes.

Thanks Jeff…that worked. I haven’t used the reports before and I followed the examples and don’t recall setting g=nil being in there. The tip off should have been checking for g not nil, LOL!

I greatly appreciate your eagle eye.

Rich