Hi,
I have created a command button on one of my forms, When the button is pressed, it does the following,
Asks the question do "Do you wish to approve the scheme"
When I select yes, it generates a report, and then prints pages 1 and 2 and another copy of page 1, it then closes the report and returns to the original form.
The following piece of code does work,
However my question is this. Is it necessary to have the DoCmd on so many lines or is it more efficient, code wise to combine the command.
If it is more efficient to combine the code please let me know.
Thanking you in advance
Private Sub btnApproveScheme_Click()
Dim Msg, Style, Title, Response, MyString
Msg = "Do you wish to approve this scheme" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "approve Local Authorities Request" ' Define title.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Forms!frmSchemeDetails!DateApp = Now()
Forms!frmSchemeDetails![Letter Printed] = True
DoCmd.OpenReport "rptApprovalLetter", acViewPreview, "", ""
DoCmd.PrintOut acPages, 1, 2, acHigh, 1, True
DoCmd.PrintOut acPages, 1, 1, acHigh, 1, True
DoCmd.Close acReport, "rptApprovalLetter", acSaveNo
DoCmd.Maximize
Else ' User chose No.
MyString = "No" ' Perform some action.
DoCmd.CancelEvent
End If
End Sub
I have created a command button on one of my forms, When the button is pressed, it does the following,
Asks the question do "Do you wish to approve the scheme"
When I select yes, it generates a report, and then prints pages 1 and 2 and another copy of page 1, it then closes the report and returns to the original form.
The following piece of code does work,
However my question is this. Is it necessary to have the DoCmd on so many lines or is it more efficient, code wise to combine the command.
If it is more efficient to combine the code please let me know.
Thanking you in advance
Private Sub btnApproveScheme_Click()
Dim Msg, Style, Title, Response, MyString
Msg = "Do you wish to approve this scheme" ' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "approve Local Authorities Request" ' Define title.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
MyString = "Yes" ' Perform some action.
Forms!frmSchemeDetails!DateApp = Now()
Forms!frmSchemeDetails![Letter Printed] = True
DoCmd.OpenReport "rptApprovalLetter", acViewPreview, "", ""
DoCmd.PrintOut acPages, 1, 2, acHigh, 1, True
DoCmd.PrintOut acPages, 1, 1, acHigh, 1, True
DoCmd.Close acReport, "rptApprovalLetter", acSaveNo
DoCmd.Maximize
Else ' User chose No.
MyString = "No" ' Perform some action.
DoCmd.CancelEvent
End If
End Sub