Hi everyone, can anybody help me with my very frustrating problem?
I have a form which contains a button named "cmd_OK", in vba I have an event "cmd_OK_Click" which contains the following code:
And then a further sub called "Close_Save" which looks like this:
And when I click the OK button I expect to see a message box stating "OK Button Pressed" followed by another stating "Close_Save macro", and then for it to run the rest of the macro.
What I get is the "OK Button Pressed" message only and nothing else.
Now, the weird thing is, if I remove all the code from the "Close_Save" sub completely, and leave on the the first msgbox line of text it seems to run fine and when I press the OK button I get both messages.
Any ideas?
I have a form which contains a button named "cmd_OK", in vba I have an event "cmd_OK_Click" which contains the following code:
Code:
Private Sub cmd_OK_Click()
MsgBox "OK Button Pressed" ' TROUBLESHOOTING MESSAGE
Close_Save
End Sub
Code:
Sub Close_Save()
MsgBox "Close_Save Macro"
If InAddMode = True Then
' IF THE FORM HAS BEEN OPENED IN ADD MODE, THEN FIRST CHECK
' THAT ALL THE REQUIRED FIELDS HAVE BEEN ENTERED
MissingField = ""
If Me.cmb_Currency.Value = 0 Then MissingField = "CURRENCY"
If Me.cmb_Country.Value = 0 Then MissingField = "COUNTRY"
If IsNull(Me.txt_PostCode) Then MissingField = "POSTCODE"
If IsNull(Me.txt_Address) Then MissingField = "ADDRESS"
If IsNull(Me.txt_CompanyName) Then MissingField = "COMPANY NAME"
If IsNull(MissingField) Then
' IF ALL FIELDS HAVE BEEN ENTERED, CLOSE AND SAVE
DoCmd.Close , , acSaveYes
Else
' IF FIELDS ARE MISSING, WARN THE USER AND GIVE THEM THE
' CHANCE TO RETRY
ch = MsgBox("You have not entered anything in the " & _
MissingField & " box." & Chr(10) & Chr(10) & _
"Select retry to go back and enter." & Chr(10) & _
"Select cancel to exit, and your new company details will not be saved.", _
vbRetryCancel, "Items Missing")
' IF CANCEL IS SELECTED, THE FORM WILL BE CLOSED AND THE
' RECORD NOT SAVED
If ch = 2 Then DoCmd.Close '(cancel selected)
End If
Else
DoCmd.Close , , acSaveYes
End If
End Sub
What I get is the "OK Button Pressed" message only and nothing else.
Now, the weird thing is, if I remove all the code from the "Close_Save" sub completely, and leave on the the first msgbox line of text it seems to run fine and when I press the OK button I get both messages.
Any ideas?