Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 300
  • Last Modified:

Print record after adding

I am printing barcode labels .  When the program starts a form appears that lets the user select a customer. After customer is selected, I close that form and open another form. I used the after insert event to print the labels. However, when I get the printout, a main form opens with a subform. The main form has customer information. The subform has item information. After I enter an item, I print a barcode. The barcode has the customer information and the information from the item just entered. I fire the print job from the After Insert event. The problem is that information from detail record does not print. I tried docmd.refreshquery
The strange thing is I can look at the connected subform database and the record is there. However, if I run a Query to extract that record it comes up blank. The code that prints the barcode is below
Private Sub Form_AfterInsert()
    Dim strReportName As String
    Dim strCriteria As String
    Dim strLpadBaleID As String
       
    'Leftpad with zeros
      strLpadBaleID = String(6 - Len(Me!txtBaleID), "0") & Me!txtBaleID
    'Format barcode field
      Me.txtBarcode = Me.txtCompanyID & strLpadBaleID
    'Report Selection    
      strReportName = "rptBarcode"
    'Set Criteria
       strCriteria = "[InvoiceNumber] = " & Me.txtInvoiceNumber & " and [BaleID]= " & Me.txtBaleID
    'Open report using criteria
      DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End sub
0
rodneygray
Asked:
rodneygray
  • 3
  • 3
1 Solution
 
mbizupCommented:
Try adding a refresh before running the report:

Private Sub Form_AfterInsert()
    Dim strReportName As String
    Dim strCriteria As String
    Dim strLpadBaleID As String
       
    'Leftpad with zeros
      strLpadBaleID = String(6 - Len(Me!txtBaleID), "0") & Me!txtBaleID
    'Format barcode field
      Me.txtBarcode = Me.txtCompanyID & strLpadBaleID
    'Report Selection    
      strReportName = "rptBarcode"
      Me.refresh '<----- Add this
    'Set Criteria
       strCriteria = "[InvoiceNumber] = " & Me.txtInvoiceNumber & " and [BaleID]= " & Me.txtBaleID
    'Open report using criteria
      DoCmd.OpenReport strReportName, acViewPreview, , strCriteria
End sub
0
 
rodneygrayAuthor Commented:
I tried the refresh. No go. What I finally did was to extract all required data into variables and passed them to the printing program. Then I used split to grab the arguments in the OnLoad event.
--------------------------------------------------------------------
Form code
---------------------------------------------------------------------
Private Sub Form_AfterInsert()
    Dim strReportName As String
    Dim strCriteria As String
    Dim strLpadBaleID As String
    Dim strPounds As String
    Dim strMoisture As String
    Dim strGrade As String
    Dim strBarcode As String
    Dim strOpenArgs As String
       
    strPounds = Me.txtPounds
    strMoisture = Me.txtMoisture
    strGrade = Me.cmboGrade
    strLpadBaleID = String(6 - Len(Me!txtBaleID), "0") & Me!txtBaleID
    Me.txtBarcode = Me.txtCompanyID & strLpadBaleID
    strBarcode = Me.txtBarcode
   
    strOpenArgs = strPounds & ";" & strMoisture & ";" & strGrade & ";" & strBarcode
   
    strReportName = "rptBarcodeTest"
    strCriteria = "[InvoiceNumber] = " & Me.txtInvoiceNumber & " and [BaleID]= " & Me.txtBaleID
    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria, , strOpenArgs

------------------------------------------------------------------------
Report Code
------------------------------------------------------------------------
Private Sub Report_Load()
    Dim x
    Dim strPounds As String
    Dim strMoisture As String
    Dim strGrade As String
    Dim strBarcode As String
    Dim strOpenArgs As String
   
    x = Split(OpenArgs, ";")
   
    strPounds = x(0)
    strMoisture = x(1)
    strGrade = x(2)
    strBarcode = x(3)
   
    Me.txtPounds = strPounds & " Lbs"
    Me.txtPounds = strPounds2 & " Lbs"
    Me.txtMoisture = strMoisture
    Me.txtMoisture2 = strMoisture
    Me.txtGrade = strGrade
    Me.txtGrade2 = strGrade
    Me.txtBarcode = strBarcode
    Me.txtBarcode2 = strBarcode
    Me.txtBarcode3 = strBarcode
    Me.txtBarcode4 = strBarcode
End Sub
0
 
Jeffrey CoachmanCommented:

Not sure this is applicable or not, but sometimes the current record needs to be saved

If me.Dirty=True then
   me.dirty=False
end if

You can reference a subform as well

  [YourSubform].Form

?

JeffCoachman
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
rodneygrayAuthor Commented:
Thought issue was resolved. However, even when passing variables to report, data from record just added does not print when going to printer. However, if I preview the report, it prints correctly every time. Any way to cause print preview to print and then close preview window?
0
 
Jeffrey CoachmanCommented:
<However, even when passing variables to report, data from record just added does not print when going to printer.>
Again, try making sure the record is saved with the Dirty Event

<Any way to cause print preview to print and then close preview window?>
Then you would need a delay in order to actually hold the report open in order to review it. correct...?

These should probably be posted as new separate questions then...
0
 
rodneygrayAuthor Commented:
boag2000: I would want the report to close immeditely. However, your me.dirtry statement did the trick.
0
 
Jeffrey CoachmanCommented:
<I would want the report to close immeditely>
    DoCmd.Close acReport, "YourReportName"
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now