Hi all!
I have several buttons in database that runs exactly same procedure (Save and Close).
In order to avoid duplicating codes I'm trying to create subroutine and call it with buttons event.. I hope it could be done..
The problem is that when subs containing codes are called they won't work (nothing happens), but code is working when used directly in button event (on_click), so I assume it has to be modified in order to work as subroutine.
Here are codes:
Close button:
Save button:
And subs are called with:
and
What I would like is to create two subs and call them from form buttons.
Is there a way to do it?
Thanks!
I have several buttons in database that runs exactly same procedure (Save and Close).
In order to avoid duplicating codes I'm trying to create subroutine and call it with buttons event.. I hope it could be done..
The problem is that when subs containing codes are called they won't work (nothing happens), but code is working when used directly in button event (on_click), so I assume it has to be modified in order to work as subroutine.
Here are codes:
Close button:
Code:
Sub Close()
If MsgBox("Save changes before closing?", vbYesNo, "Saving...") = vbYes Then
DoCmd.Save
Else
If Me.Dirty = True Then DoCmd.RunCommand acCmdUndo
End If
DoCmd.Close
Save button:
Code:
Sub Save()
Dim strMsg As String
Dim iResponse As Integer
strMsg = "Do you wish to save the changes?" & Chr(10) & _
"Click Yes to Save or No to Discard changes."
iResponse = MsgBox(strMsg, vbQuestion + vbYesNo, "Save Record?")
If iResponse = vbNo Then
If Me.Dirty = True Then DoCmd.RunCommand acCmdUndo
Else
Me.Dirty = False
DoCmd.Close
End If
And subs are called with:
Code:
Private Sub cmdSave_Click()
Save
End Sub
Code:
Private Sub cmdClose()
Close
End Sub
What I would like is to create two subs and call them from form buttons.
Is there a way to do it?
Thanks!