Hello -
I'm trying to close a form thru vba, but I'm unable to do so! This is so frustrating not being able to do such a simple thing.
What I have is that when a user creates a new record, the vba code will immediately change some data, and then prompt the user if they want to save. If they choose no, the changes are rolled back, and the form SHOULD close, but it doesn't.
Here's my code:
The code just seems to ignore the docmd.close line. This is in the OnCurrent Event of the form, does this have anything to do with it? Does anyone know what I'm doing wrong?
THanks!!!!
I'm trying to close a form thru vba, but I'm unable to do so! This is so frustrating not being able to do such a simple thing.
What I have is that when a user creates a new record, the vba code will immediately change some data, and then prompt the user if they want to save. If they choose no, the changes are rolled back, and the form SHOULD close, but it doesn't.
Here's my code:
Code:
If Me.NewRecord Then
Me.custid_hidden.SetFocus
Me.custid_hidden.Text = "29"
If MsgBox("Do you want to save?", vbYesNo) = vbNo Then
Me.Undo
DoCmd.Close acForm, Me.Name, acSaveNo
Exit Sub
Else
DoCmd.RunCommand acCmdSaveRecord
End If
End If
The code just seems to ignore the docmd.close line. This is in the OnCurrent Event of the form, does this have anything to do with it? Does anyone know what I'm doing wrong?
THanks!!!!