Solved

Print record after adding

Posted on 2011-09-23
7
291 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

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…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

815 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

7 Experts available now in Live!

Get 1:1 Help Now