VBA to save a record before it's printed (1 Viewer)

ewan97

Registered User.
Local time
Today, 06:40
Joined
Nov 17, 2014
Messages
27
Hi, I need to save a new record from a form before it gets printed, the vba code behind the print button at the minute just opens the report and inserts the record in it. I need to put something in before that to save the record when the button is clicked.
The form in question is frmPlaceOrderFinal and I'm referring to the print button (command17). I've attached my system as well as an image for reference.

the code that is currently behind the button:
Code:
Private Sub Command17_Click()

Dim strDocName As String
Dim strWhere As String
    strDocName = "rptFinalInvoice"
    strWhere = "[InvoiceID]=" & Me!InvoiceID
    DoCmd.OpenReport strDocName, acPreview, , strWhere
    
End Sub
I need to save the record before it is opened in the report
Thanks
 

Attachments

  • ewan_DBsytem.zip
    245.4 KB · Views: 83
  • reference_image.jpg
    reference_image.jpg
    79.4 KB · Views: 116

spikepl

Eledittingent Beliped
Local time
Today, 07:40
Joined
Nov 3, 2010
Messages
6,142
Insert

Me.dirty=False

as forst executable line in your command17_click thing.

Remeber that in the longer term it pays to name controls and buttons for what they do, not just leaving the Access-assigned "command17" etc.

Finally, I'd recommend you work on your google and AWF search skills, This is a simple question you ought to find the answer to in a few seconds. Googling is just as important as coding.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 06:40
Joined
Sep 12, 2006
Messages
15,709
note that you may need to add some error checking

when you do

me.dirty = false
(or runcommand accmdsaverecord)

the action may fail because the record is incomplete (or for other reasons), in which you need to intercept and deal with the error message.
 

Users who are viewing this thread

Top Bottom