Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combined Save and Print button 1

Status
Not open for further replies.

Antonimo

Technical User
Jun 26, 2003
86
SE
I have found some excellent posts on printing form contents, but nothing quite answers my query.

I have a fairly simple form to be filled in by an operator. I would like the last record that has been entered into the form to be printed out at the same time as saving the record.

How do I create a command button to achieve this?

Thanks in advace.
 
Something like this should do it......

Code:
On Error GoTo Err_Command7_Click

        DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Dim stDocName As String
    stDocName = "Contract Reports"
    DoCmd.OpenReport stDocName, acViewNormal, , "[ID]=" & [ID]

Exit_Command7_Click:
    Exit Sub

Err_Command7_Click:
    MsgBox Err.Description
    Resume Exit_Command7_Click
 
something like this?
Code:
Private Sub Button_Click()
'save record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

'print form
    Dim strReportName As String
      
     strReportName = "rprtFactuur"
     DoCmd.OpenReport strReportName, acViewPreview
End Sub


Pampers [afro]
Just became father!
 
Thanks djwatts for your quick reply.

I have just lost the vpn connection to the computer I was trying this on, but as soon as I am able to re-establish the connection, I shall test your code and report back.
 
Thanks Pampers,

I shall also try your approach when I re-connect.

BTW - Congratulations on becoming a father! Great isn't it?
 
Hi Antonimo,
Mij approach is very similar to djwatt, only he includes a where-clause (Id = Me.Id)

BTW: sure is!

Pampers [afro]
Just became father!
 
I have tried the code supplied by djwatts, but clicking on the command button gave me an error, "Microsoft Access can't find the field '|' referred to in your expression". I do not understand thie and I cannot find a '|' in the expression.

However, I used the code from pampers, with the command button being named "pampers":

Code:
Private Sub pampers_Click()
'save record
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

'print form
    Dim strReportName As String
      
     strReportName = "MailingList"
     DoCmd.OpenReport strReportName, acViewPreview
End Sub

I needed to create a report called "MailingList" to make it work. On clicking the button, a report is produced.

How do I have this form sent to the printer as it would be using the following:

Code:
Private Sub PrintRecord_Click()
On Error GoTo Err_PrintRecord_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.PrintOut acSelection

Exit_PrintRecord_Click:
    Exit Sub

Err_PrintRecord_Click:
    MsgBox Err.Description
    Resume Exit_PrintRecord_Click
    
End Sub

and combining it with the "save record" so that there is only one button?
 
Hi Antonimo,
The report you see is a so called printpreview (acViewPreview). Which is a common way to check your output before really sending it to the printer. If you right click on this reportpreview, a dialog appears with an option to print the report. If you don't want this extra step, you can use a straight:
DoCmd.PrintOut "MailingList".



Pampers [afro]
You never too young to learn
 
Hi pampers,

Thanks again! Your last post worked well to show me how to print out the report.

Is it possible to print out just the single page from the report containing the current record?
 
Have a look at the 4th argument of the OpenReport method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hi PH,

Thanks for your response. Could you be a little more specific?

 
PHV means the section after the third comma ie "[ID]=" & [ID]"
in this case and in DJwatts reply.

DoCmd.OpenReport stDocName, acViewNormal, , "[ID]=" & [ID]"

As a matter of interest I created a small form with PRINT and CANCEL buttons on it, which opens along with the report when it is previewed. It also closes itself and the report after clicking on either of the buttons.



Ian Mayor (UK)
Program Error
There's ALWAYS more than one way to skin a cat!
But only one way to get it RIGHT!
 
Hello Ian,

Some time ago you wrote

"As a matter of interest I created a small form with PRINT and CANCEL buttons on it, which opens along with the report when it is previewed. It also closes itself and the report after clicking on either of the buttons."

Is there any way of being able to see this form?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top