Solved

Print record after adding

Posted on 2011-09-23
7
289 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
  • 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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now