Newbie - Exit w/o updating

  • Thread starter Thread starter Bumbino
  • Start date Start date
B

Bumbino

I have a new database and I want to give the user a chance to exit the form
without the info they have entered into the controls being added to the
table. There are 5 controls but when they select the exit button, anything
that they have entered still gets saved to the table. This happens even if
they have only entered text into 1 control. Any help would be appreciated.
 
I have a new database and I want to give the user a chance to exit the form
without the info they have entered into the controls being added to the
table. There are 5 controls but when they select the exit button, anything
that they have entered still gets saved to the table. This happens even if
they have only entered text into 1 control. Any help would be appreciated.

Partly user training, partly database design.

The user can hit <Esc><Esc> to undo what they've done on the form.

In addition, or instead, you can put VBA code in the Form's BeforeUpdate event
to check that everything is filled in:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If IsNull(Me!ThisControl) Then
Cancel = True
iAns = MsgBox("Fill in ThisControl or click Cancel to erase form", _
vbOKCancel)
If iAns = vbCancel Then
Me.Undo
End If
End If
<etc for the other controls>
End Sub

John W. Vinson [MVP]
 
In addition to John's suggestions, you can add an <Undo> command button.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Put a cancel button on the form call it cmdCancel.
--type the word Cancel onto the button itself
--in design view of the form click the cancel button
--on the property dialog, on the event tab
--find On Click, click the button with the ellipsis(...) for On Click
--choose Code builder
--the VBA editor opens
--You will see
Private Sub cmdCancel_Click()
End Sub
type in these lines
If Me.Dirty = True Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name

The whole thing will look like this
Private Sub cmdCancel_Click()
If Me.Dirty = True Then
Me.Undo
End If
DoCmd.Close acForm, Me.Name
End Sub

When the user clicks Cancel, any changes will be undone and the form will
close.

Jeanette Cunningham
 
John W. Vinson said:
Partly user training, partly database design.

The user can hit <Esc><Esc> to undo what they've done on the form.

In addition, or instead, you can put VBA code in the Form's BeforeUpdate
event
to check that everything is filled in:

Private Sub Form_BeforeUpdate(Cancel as Integer)
Dim iAns As Integer
If IsNull(Me!ThisControl) Then
Cancel = True
iAns = MsgBox("Fill in ThisControl or click Cancel to erase form", _
vbOKCancel)
If iAns = vbCancel Then
Me.Undo
End If
End If
<etc for the other controls>
End Sub

John W. Vinson [MVP]

I see you have no expertise in programming whatsoever.
Dim iAns As Integer

"i" is not acceptable Hungarian notation for integers that are not used as
index pointers. Use "n".

I bet the contents of Fort Knox's bullion vaults to the contents of your
empty head that you have to go and look up Hungarian notation in a wiki,
too.

HTH HAND
 
Troll

--
--
Terry Kreft


msnews.microsoft.com said:
I see you have no expertise in programming whatsoever.


"i" is not acceptable Hungarian notation for integers that are not used as
index pointers. Use "n".

I bet the contents of Fort Knox's bullion vaults to the contents of your
empty head that you have to go and look up Hungarian notation in a wiki,
too.

HTH HAND
 

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

Back
Top