Multiple Subs (1 Viewer)

kesam

Registered User.
Local time
Today, 14:12
Joined
Aug 19, 2003
Messages
12
As a complete novice but eager to learn I hope someone can help.

It's a pretty general thing. I want to press a command button and do 3 things.

1 Save the current form record
2 show a message box
3 Print a report based on the current record.

As I say I'm kean to learn and have figured out the code for all of the above separately but I don't know how the layout should be to perform three different subs from opne button

Any help would be great

Thanks

Kev
 
kesam said:
It's a pretty general thing. I want to press a command button and do 3 things.

1 Save the current form record
2 show a message box
3 Print a report based on the current record.

As I say I'm kean to learn and have figured out the code for all of the above separately but I don't know how the layout should be to perform three different subs from opne button

Basically, you just do them in the order you want to do it:

Code:
Private Sub MyButton_Click()
    DoCmd.RunCommand acCmdSaveRecord
    MsgBox "Your record has been saved.", vbInformation
    DoCmd.OpenReport "MyReport", acViewPreview
End Sub

What might be nicer is to offer the user the option of printing the record:

Code:
Private Sub MyButton_Click()
    DoCmd.RunCommand acCmdSaveRecord
    If MsgBox("Your record has been saved.", vbQuestion + vbYesNo) =vbYes Then
        DoCmd.OpenReport "MyReport", acViewPreview
    End If
End Sub
 
Thanks,

I was trying to put subs inside subs(which now seems pretty stupid).

Kev
 
kesam said:
I was trying to put subs inside subs(which now seems pretty stupid).

Yes, putting subs within subs is incorrect. You can, however, call subs from other subs. i.e

Code:
Private Sub MyButton_Click()
    DoCmd.RunCommand acCmdSaveRecord
    Call ShowMessage
End Sub

Private Sub ShowMessage()
    MsgBox "This is in another sub.", vbInformation
End Sub
 

Users who are viewing this thread

Back
Top Bottom