By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,300 Members | 1,682 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,300 IT Pros & Developers. It's quick & easy.

Idiot Question: Why do I get a propety Error with the following code?

P: n/a
Hi,

As a test to help a friend find out where some code was malfunctioning
I wrote the code below for a very simple form with an 'update' chekcing
routine...

The problem is that I get 1 of 2 errors depnding on whetehr or not
I include some code in the code for closing the form...

If I Include the code I get an error message about an invalid value for a
propety setting (I'm assuming that if I cancel an update I can't clear
Me.Dirty..) If I remove the If Me.Dirty lines then the otherwise
documented 'close bug' seems to manifest.

Suggestions for getting the code to work flawlessly in all
situations would be appreciated.

FMNT80
Full Form code


Option Compare Database
Dim no_exit As Boolean
'

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

If Me.Dirty Then Me.Dirty = False
DoCmd.Close

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(txt_id.Value) Then
If MsgBox("Abort?", vbYesNo) = vbYes Then
Me.Undo
Cancel = False
supress_exit = False
Else
Cancel = True
supress_exit = True
End If
Else
x = MsgBox("Save?", vbYesNoCancel)
If x = vbYes Then
no_exit = False
ElseIf x = vbNo Then
Form.Undo
no_exit = False
Else
Cancel = True
no_exit = True
End If
End If
End Sub

Private Sub Form_Current()
no_exit = False
End Sub

Private Sub Form_Load()
no_exit = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
If no_exit Then
Cancel = True
no_exit = False
End If
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In the Form BeforeUpdate event Cancel = True will stop the update.
You've set the Cancel to False when it should be True.

Command1 OnClick event should have Me.Undo instead of Me.Dirty = False.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQfbLvYechKqOuFEgEQKNNQCfdMRwv5BXy/IdGmMpOsG3kUO2PLAAoPy6
3Vywg/5eUyIOxaP/hCx12UG1
=ZCg6
-----END PGP SIGNATURE-----
Privacy Trap wrote:
Hi,

As a test to help a friend find out where some code was malfunctioning
I wrote the code below for a very simple form with an 'update' chekcing
routine...

The problem is that I get 1 of 2 errors depnding on whetehr or not
I include some code in the code for closing the form...

If I Include the code I get an error message about an invalid value for a
propety setting (I'm assuming that if I cancel an update I can't clear
Me.Dirty..) If I remove the If Me.Dirty lines then the otherwise
documented 'close bug' seems to manifest.

Suggestions for getting the code to work flawlessly in all
situations would be appreciated.

FMNT80

Full Form code

Option Compare Database
Dim no_exit As Boolean
'

Private Sub Command1_Click()
On Error GoTo Err_Command1_Click

If Me.Dirty Then Me.Dirty = False
DoCmd.Close

Exit_Command1_Click:
Exit Sub

Err_Command1_Click:
MsgBox Err.Description
Resume Exit_Command1_Click

End Sub

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(txt_id.Value) Then
If MsgBox("Abort?", vbYesNo) = vbYes Then
Me.Undo
Cancel = False
supress_exit = False
Else
Cancel = True
supress_exit = True
End If
Else
x = MsgBox("Save?", vbYesNoCancel)
If x = vbYes Then
no_exit = False
ElseIf x = vbNo Then
Form.Undo
no_exit = False
Else
Cancel = True
no_exit = True
End If
End If
End Sub

Private Sub Form_Current()
no_exit = False
End Sub

Private Sub Form_Load()
no_exit = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
If no_exit Then
Cancel = True
no_exit = False
End If

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.