Save and print at the same time?

  • Thread starter Thread starter Bruce
  • Start date Start date
B

Bruce

I have a form that includes a command button to print the
report that is based on the current record. However, when
I fill in the information and print, I end up with a blank
form unless I go to the previous record, close the form,
or some other activity. I know I can add a Save button to
the form, but I would prefer that each field be saved as
it is entered, or otherwise have it so that when the print
button is clicked it prints the information I just entered.
Perhaps save and print could be a combined button?

I used the command button wizard to add a Print button to
the form, and added code (provided in this forum) so that
it prints only the current record. This is the code to
which I would add a Save command, if that is the best
choice for my needs:

Private Sub cmdPrintForm_Click()

'Open the report to display only the current record

Dim DocName As String
Dim LinkCriteria As String

stLinkCriteria = "[ID]=" & Me![ID]
stDocName = "rptSpecReview"
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit Sub
End Sub

cmdPrintForm is the command button, [ID] is the record's
unique identifier, and rptSpecReview is the report that is
printed by clicking the command button.
 
Add this line befor stLinkCriteria=...

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70


HTH
kes
 
Private Sub cmdPrintForm_Click()

'Open the report to display only the current record

Dim DocName As String
Dim LinkCriteria As String

stLinkCriteria = "[ID]=" & Me![ID]
stDocName = "rptSpecReview"
DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

Exit Sub
End Sub

Just add a line

DoCmd.RunCommand acCmdSaveRecord

before the OpenReport.
 
Thanks to both. I chose the shortest solution first
(DoCmd.RunCommand acCmdSaveRecord). If I understand
correctly, the other suggestion accomplishes much the same
thing by drilling down through the Records menu. If my
understanding is in error I would be interested in
learning more, but in any case thanks for the help.
 
Thanks to both. I chose the shortest solution first
(DoCmd.RunCommand acCmdSaveRecord). If I understand
correctly, the other suggestion accomplishes much the same
thing by drilling down through the Records menu. If my
understanding is in error I would be interested in
learning more, but in any case thanks for the help.

Your understanding is correct. The menu solution is still
(unaccountably, in my opinion) used by the Microsoft wizards, and it
does work.

There's actually an even simpler, and even more obscure, way to force
Access to save a record:

Me.Dirty = True
 
Back
Top