cancelling the docmd.close function clears text boxes

  • Thread starter dustinw101 via AccessMonster.com
  • Start date
D

dustinw101 via AccessMonster.com

I have placed a close button on my form. If the user clicks on the close
button, the form is first checked if it is dirty. If the form is dirty then
I have a msg box that fires and tell the user that they have to save or undo
the entries to the form before they can exit. When the user hits the OK
button on the message box, any data that they had just entered into any of
the text fields is cleared out. How do I stop this from happening.
Why is this happening?
 
D

dustinw101 via AccessMonster.com

Ok, so after a little more testing I did find that if I use the mouse to
click on the cmdCloseForm button and I get the msgbox error that I have setup
it does not clear out an text that I jsut entered in any of the text fields,
however, if I use the escape key, it will clear out text fields.

Here is the code that I have written in the form:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF9
If cmdSave.Enabled = True Then
Call cmdSave_Click
End If
Case vbKeyF10
If cmdUndo.Enabled = True Then
Call cmdUndo_Click
End If
Case vbKeyF12
If cmdUnlockFields.Enabled = True Then
Call cmdUnlockFields_Click
End If
Case vbKeyEscape
Call cmdCloseForm_Click
End Select

End Sub
-------------------------------
Private Sub cmdCloseForm_Click()
If Me.Dirty Then
MsgBox "You Must Save or Cancel the Current Entry Before You Can Exit",
vbOKOnly + vbExclamation, "Error"
Exit Sub
Else
DoCmd.Close
End If
End Sub



Can you post your code for the close button?
I have placed a close button on my form. If the user clicks on the close
button, the form is first checked if it is dirty. If the form is dirty then
[quoted text clipped - 3 lines]
the text fields is cleared out. How do I stop this from happening.
Why is this happening?
 
J

JString

That's the default esc key behavior in Access. Are you trying to hit esc to
'cancel' out of the message box?

dustinw101 via AccessMonster.com said:
Ok, so after a little more testing I did find that if I use the mouse to
click on the cmdCloseForm button and I get the msgbox error that I have setup
it does not clear out an text that I jsut entered in any of the text fields,
however, if I use the escape key, it will clear out text fields.

Here is the code that I have written in the form:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF9
If cmdSave.Enabled = True Then
Call cmdSave_Click
End If
Case vbKeyF10
If cmdUndo.Enabled = True Then
Call cmdUndo_Click
End If
Case vbKeyF12
If cmdUnlockFields.Enabled = True Then
Call cmdUnlockFields_Click
End If
Case vbKeyEscape
Call cmdCloseForm_Click
End Select

End Sub
-------------------------------
Private Sub cmdCloseForm_Click()
If Me.Dirty Then
MsgBox "You Must Save or Cancel the Current Entry Before You Can Exit",
vbOKOnly + vbExclamation, "Error"
Exit Sub
Else
DoCmd.Close
End If
End Sub



Can you post your code for the close button?
I have placed a close button on my form. If the user clicks on the close
button, the form is first checked if it is dirty. If the form is dirty then
[quoted text clipped - 3 lines]
the text fields is cleared out. How do I stop this from happening.
Why is this happening?
 
J

Jon Lewis

Try this in your Form_KeyDown Select Case construct
Case vbKeyEscape
KeyCode = 0 'Cancel default Escape behaviour
Call cmdCloseForm_Click

HTH

dustinw101 via AccessMonster.com said:
Ok, so after a little more testing I did find that if I use the mouse to
click on the cmdCloseForm button and I get the msgbox error that I have
setup
it does not clear out an text that I jsut entered in any of the text
fields,
however, if I use the escape key, it will clear out text fields.

Here is the code that I have written in the form:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyF9
If cmdSave.Enabled = True Then
Call cmdSave_Click
End If
Case vbKeyF10
If cmdUndo.Enabled = True Then
Call cmdUndo_Click
End If
Case vbKeyF12
If cmdUnlockFields.Enabled = True Then
Call cmdUnlockFields_Click
End If
Case vbKeyEscape
Call cmdCloseForm_Click
End Select

End Sub
-------------------------------
Private Sub cmdCloseForm_Click()
If Me.Dirty Then
MsgBox "You Must Save or Cancel the Current Entry Before You Can Exit",
vbOKOnly + vbExclamation, "Error"
Exit Sub
Else
DoCmd.Close
End If
End Sub



Can you post your code for the close button?
I have placed a close button on my form. If the user clicks on the
close
button, the form is first checked if it is dirty. If the form is dirty
then
[quoted text clipped - 3 lines]
the text fields is cleared out. How do I stop this from happening.
Why is this happening?
 

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