Sorry, I don't see the problem.
--
Dave Hargis, Microsoft Access MVP
:
Thanks again fro helping.
I tried to do undo, but it is the same.
Interestinmgis the code working on the Windows "X" and set breakpoint to run
step by step.
It only fails when user click on "NO" on the button when program prompt users.
Any ideas?
:
Is the error on this line:
Cancel = VerifyCloseForm
If not, which line is highlighted when the error occurs?
Also, I just notices anther thing that you should do. If the user clicks no
so the record is not saved, you should undo it:
Private Function VerifyCloseForm() As Boolean
If (DCount("*", "MyTable", "[MyID] = " & cmbMyfield.Value ) = 0 Then
If MsgBox("Your data has not been saved, are you sure ", vbYesNo) =
vbNo Then
VerifyCloseForm = True
Else
Me.Undo
VerifyCloseForm = False
End If
End If
End Function
--
Dave Hargis, Microsoft Access MVP
:
It is fired, but the issue is I got error message wehn I click on no.
I got "you enter an expression that has an invalid reference to the property
|."
It seems that it failed when I set cancel to true.
:
Good,
What did you do to make it start working?
--
Dave Hargis, Microsoft Access MVP
:
I got message box. It must fired.
I checked with breakpoint too.
:
Not enought coffee yet. I thought I read it saying False.
Did you try debugging with a breakpoint to see if the Unload event is firing
when you click your button?
--
Dave Hargis, Microsoft Access MVP
:
Thanks for the message,
The unload triggle and the Cancel property to set true when user answer no
on the message box.
The following code is in the function:
If MsgBox("Your data has not been saved, are you sure ", vbYesNo) =
vbNo Then
VerifyCloseForm = True
End If
I only got the message when I click no on the message box.
Thanks again,
:
Very strange. I just ran a test on a form where I do almost exactly the same
thing.
The only major difference is I use:
Docmd.Close acForm, Me.Name, acSaveNo
I put a breakpoint on the first line in the Unload event and it did stop
there.
I do see one problem in your code. VerifyCloseForm will always return
false. You set it to false in the beginning of the function but nowhere in
the function do you set it to True.
Try running it with a break point to ensure it is not firing.
--
Dave Hargis, Microsoft Access MVP
:
Here is my code,
Private Sub cmdCancel_Click()
DoCmd.Close
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = VerifyCloseForm
End Sub
Private Function VerifyCloseForm() As Boolean
VerifyCloseForm = False
If (DCount("*", "MyTable", "[MyID] = " & cmbMyfield.Value ) = 0 Then
If MsgBox("Your data has not been saved, are you sure ", vbYesNo) =
vbNo Then
VerifyCloseForm = True
End If
End If
End Function
I have a button to close the form. (docmd.close)
I call a function to validate unload.
If user answer the promt vbNo then I set the cancel to true.
The unload works fine, itf I click on the Windows "X" close button, but not
my close command button.
Thanks again,
Your help is great appreciated,
:
Post your code so we can see if there is something there causing the problem.
Docmd.Close will fire the Unload, then the Close Event. If the current
record has been changed but not updated, it will fire the Before Update,
After Update events before the Unload as well.
--
Dave Hargis, Microsoft Access MVP
:
I have a button to close the form and call DoCmd.Close
I have code in unload to verify before close. If user did not savwe
information than ask user to make sure close the form.
The unload works if I click on "X" button.
I got "you enter an expression that has an invalid reference to the property
|." when I use the button and click no to keep form open.
I beleive that the docmd.close triggle the unload event and something wrong
when I set cancel property to true on Unload event.
Are there any workaround?
Your help is great appreciated,