Solved

Print record after adding

Posted on 2011-09-23
7
295 Views
Last Modified: 2012-06-21
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
Comment
Question by:rodneygray
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 36586862
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
 
LVL 1

Author Comment

by:rodneygray
ID: 36587121
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
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 36587651

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:rodneygray
ID: 36588232
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
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36588513
<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
 
LVL 1

Author Comment

by:rodneygray
ID: 36590074
boag2000: I would want the report to close immeditely. However, your me.dirtry statement did the trick.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36590454
<I would want the report to close immeditely>
    DoCmd.Close acReport, "YourReportName"
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question