onformunload

S

Souris

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,
 
K

Klatuu

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.
 
S

Souris

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,
 
K

Klatuu

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


Souris said:
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,


Klatuu said:
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.
 
S

Souris

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,

Klatuu said:
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


Souris said:
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,


Klatuu said:
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,
 
K

Klatuu

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


Souris said:
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,

Klatuu said:
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


Souris said:
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,
 
S

Souris

yes, it is fired.


Klatuu said:
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


Souris said:
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,

Klatuu said:
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,
 
S

Souris

I got message box. It must fired.
I checked with breakpoint too.



Klatuu said:
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


Souris said:
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,

Klatuu said:
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,
 
K

Klatuu

Good,
What did you do to make it start working?
--
Dave Hargis, Microsoft Access MVP


Souris said:
I got message box. It must fired.
I checked with breakpoint too.



Klatuu said:
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


Souris said:
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,
 
S

Souris

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.



Klatuu said:
Good,
What did you do to make it start working?
--
Dave Hargis, Microsoft Access MVP


Souris said:
I got message box. It must fired.
I checked with breakpoint too.



Klatuu said:
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,
 
K

Klatuu

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


Souris said:
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.



Klatuu said:
Good,
What did you do to make it start working?
--
Dave Hargis, Microsoft Access MVP


Souris said:
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,
 
S

Souris

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?




Klatuu said:
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


Souris said:
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.



Klatuu said:
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,
 
K

Klatuu

Sorry, I don't see the problem.
--
Dave Hargis, Microsoft Access MVP


Souris said:
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?




Klatuu said:
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


Souris said:
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,
 
S

Souris

Thanks for helping,
This is I got from VBA help.

No current record. (Error 3021)
This error occurs after the unsuccessful application of one of the Find
methods or the Seek method, when the underlying Recordset contains no records
or the record has been deleted. Move to or select another record, and try the
operation again. If the Recordset is empty, you cannot position to a current
record. Check the BOF and EOF properties.

Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click

DoCmd.Close acForm, "Myform", acSaveNo



Err_cmdCancel_Click:
Exit Sub

End Sub

I use above code as a solution.
Can you please let me know am I on the right track?
Thanks again for helping,


Klatuu said:
Sorry, I don't see the problem.
--
Dave Hargis, Microsoft Access MVP


Souris said:
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?




Klatuu said:
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,
 
K

Klatuu

Is that working for you?
The info is correct, but I was not aware you were getting that error.
--
Dave Hargis, Microsoft Access MVP


Souris said:
Thanks for helping,
This is I got from VBA help.

No current record. (Error 3021)
This error occurs after the unsuccessful application of one of the Find
methods or the Seek method, when the underlying Recordset contains no records
or the record has been deleted. Move to or select another record, and try the
operation again. If the Recordset is empty, you cannot position to a current
record. Check the BOF and EOF properties.

Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click

DoCmd.Close acForm, "Myform", acSaveNo



Err_cmdCancel_Click:
Exit Sub

End Sub

I use above code as a solution.
Can you please let me know am I on the right track?
Thanks again for helping,


Klatuu said:
Sorry, I don't see the problem.
--
Dave Hargis, Microsoft Access MVP


Souris said:
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,
 
S

Souris

Thnaks for the message,
It does not show the message for the user.
It is kind hide error.
It is working, but I am not sure is the right way to do it.

Thanks again,

Klatuu said:
Is that working for you?
The info is correct, but I was not aware you were getting that error.
--
Dave Hargis, Microsoft Access MVP


Souris said:
Thanks for helping,
This is I got from VBA help.

No current record. (Error 3021)
This error occurs after the unsuccessful application of one of the Find
methods or the Seek method, when the underlying Recordset contains no records
or the record has been deleted. Move to or select another record, and try the
operation again. If the Recordset is empty, you cannot position to a current
record. Check the BOF and EOF properties.

Private Sub cmdCancel_Click()
On Error GoTo Err_cmdCancel_Click

DoCmd.Close acForm, "Myform", acSaveNo



Err_cmdCancel_Click:
Exit Sub

End Sub

I use above code as a solution.
Can you please let me know am I on the right track?
Thanks again for helping,


Klatuu said:
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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top