Problem Closing Forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

We have several forms which require certain fields to be completed which is
fine and we do not want to change. However users begin entering data on to a
form and then then decide to they'll do it later instead.

This immediately causes problems closing because of the required fields. Is
there any way we could insert a cancel button on to the form or is there
another way around this?

Ian
 
Hi, Ian.
Is
there any way we could insert a cancel button on to the form or is there
another way around this?

Yes. Create an "Undo" button. Try:

Private Sub CancelBtn_Click()

On Error GoTo ErrHandler

Me.Undo

Exit Sub

ErrHandler:

MsgBox "Error in CancelBtn_Click( ) in " & vbCrLf & Me.Name & _
" form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & Err.Description
Err.Clear

End Sub

.... where CancelBtn is the name of the button.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips.

(Please remove ZERO_SPAM from my reply E-mail address so that a message will
be forwarded to me.)
- - -
If my answer has helped you, please sign in and answer yes to the question
"Did this post answer your question?" at the bottom of the message, which
adds your question and the answers to the database of answers. Remember that
questions answered the quickest are often from those who have a history of
rewarding the contributors who have taken the time to answer questions
correctly.
 
This immediately causes problems closing because of the required fields. Is
there any way we could insert a cancel button on to the form

Sure. Create a button (turn off the wizard first); name it cmdCancel,
or whatever you want, and set its Caption to Cancel or whatever you
want the button to say. View its Properties and click the ... icon by
the Click event on the Events tab; select Code Builder; and edit the
code to

Private Sub cmdCancel_Click()
Me.Undo
End Sub

or to protect the user from unintentionally erasing all their work,

Private Sub cmdCancel_Click()
Dim iAns As Integer
iAns = MsgBox("Cancel this record?", vbYesNo)
If iAns = vbYes Then
Me.Undo
End If
End Sub


John W. Vinson[MVP]
 
That was easy thanks very much mate.

John Vinson said:
Sure. Create a button (turn off the wizard first); name it cmdCancel,
or whatever you want, and set its Caption to Cancel or whatever you
want the button to say. View its Properties and click the ... icon by
the Click event on the Events tab; select Code Builder; and edit the
code to

Private Sub cmdCancel_Click()
Me.Undo
End Sub

or to protect the user from unintentionally erasing all their work,

Private Sub cmdCancel_Click()
Dim iAns As Integer
iAns = MsgBox("Cancel this record?", vbYesNo)
If iAns = vbYes Then
Me.Undo
End If
End Sub


John W. Vinson[MVP]
 
This is what I want to do but I have a sub form . Will this work for both?
Thank you,
Pixie
 
Back
Top