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.
John W. Vinson - 18 Jan 2008 23:26 GMT
>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]
msnews.microsoft.com - 19 Jan 2008 01:51 GMT
>>I have a new database and I want to give the user a chance to exit the
>>form
[quoted text clipped - 28 lines]
>
> 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
Terry Kreft - 19 Jan 2008 13:06 GMT
Troll

Signature
--
Terry Kreft
>>>I have a new database and I want to give the user a chance to exit the
>>>form
[quoted text clipped - 41 lines]
>
> HTH HAND
msnews.microsoft.com - 20 Jan 2008 04:38 GMT
> Troll
Wow! You're sharp!
Terry Kreft - 20 Jan 2008 23:13 GMT
Troll feeding

Signature
--
Terry Kreft
>> Troll
>
> Wow! You're sharp!
msnews.microsoft.com - 21 Jan 2008 00:23 GMT
> Troll feeding
Gimme more.
Jeff Boyce - 19 Jan 2008 00:36 GMT
In addition to John's suggestions, you can add an <Undo> command button.
Regards
Jeff Boyce
Microsoft Office/Access MVP
>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
[quoted text clipped - 4 lines]
> they have only entered text into 1 control. Any help would be
> appreciated.
Jeanette Cunningham - 19 Jan 2008 00:43 GMT
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
>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
[quoted text clipped - 4 lines]
> they have only entered text into 1 control. Any help would be
> appreciated.