Group:  Microsoft Access ยป microsoft.public.access.formscoding
Thread: clearing and closing a form

Geek News

clearing and closing a form
Brandon P 12/11/2008 3:03:19 PM
I have a form that contains a linked subform. It is being used as a data
entry screen. If someone begins typing into the form (either the form or the
subform) it inserts a record if they simply stop inputing the information and
close the form. I need a way to close the form and to not add any record that
may have been started.

So far I've tried the following:

1. I've turned off the "Close Button" to require the use of a command button
2. I've tried to use the DoCmd.RunCommand to use the menu option to delete
the record. I would set the focus on the subform, run the command and do the
same for the main form. The only problem if no record was added--I get an
error and it stops processing the code.

I tried to figure out how to test the subform and the form for a record and
then use the delete command, but have be unsuccessful at that.

Help would greatly be appreciated.

TIA,
:Brandon:
Re: clearing and closing a form
"Allen Browne" <AllenBrowne[ at ]SeeSig.Invalid> 12/11/2008 3:06:23 PM
The *only* way to trap the save in a bound form is to use the BeforeUpdate
event procedure of the form.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Msgbox("Save?", vbYesNo, "Confirm") = vbNo Then
Cancel = True
Me.Undo
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Brandon P" <BrandonP[ at ]discussions.microsoft.com> wrote in message
news:6FEC0C20-BAF3-4D40-8C0C-28C3C5FC9D80[ at ]microsoft.com...
[Quoted Text]
>I have a form that contains a linked subform. It is being used as a data
> entry screen. If someone begins typing into the form (either the form or
> the
> subform) it inserts a record if they simply stop inputing the information
> and
> close the form. I need a way to close the form and to not add any record
> that
> may have been started.
>
> So far I've tried the following:
>
> 1. I've turned off the "Close Button" to require the use of a command
> button
> 2. I've tried to use the DoCmd.RunCommand to use the menu option to delete
> the record. I would set the focus on the subform, run the command and do
> the
> same for the main form. The only problem if no record was added--I get an
> error and it stops processing the code.
>
> I tried to figure out how to test the subform and the form for a record
> and
> then use the delete command, but have be unsuccessful at that.
>
> Help would greatly be appreciated.
>
> TIA,
> :Brandon:

Re: clearing and closing a form
Brandon P 12/11/2008 3:19:01 PM
Thanks for the help. This solution will work very well for my needs.

"Allen Browne" wrote:

[Quoted Text]
> The *only* way to trap the save in a bound form is to use the BeforeUpdate
> event procedure of the form.
>
> Private Sub Form_BeforeUpdate(Cancel As Integer)
> If Msgbox("Save?", vbYesNo, "Confirm") = vbNo Then
> Cancel = True
> Me.Undo
> End If
> End Sub
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Brandon P" <BrandonP[ at ]discussions.microsoft.com> wrote in message
> news:6FEC0C20-BAF3-4D40-8C0C-28C3C5FC9D80[ at ]microsoft.com...
> >I have a form that contains a linked subform. It is being used as a data
> > entry screen. If someone begins typing into the form (either the form or
> > the
> > subform) it inserts a record if they simply stop inputing the information
> > and
> > close the form. I need a way to close the form and to not add any record
> > that
> > may have been started.
> >
> > So far I've tried the following:
> >
> > 1. I've turned off the "Close Button" to require the use of a command
> > button
> > 2. I've tried to use the DoCmd.RunCommand to use the menu option to delete
> > the record. I would set the focus on the subform, run the command and do
> > the
> > same for the main form. The only problem if no record was added--I get an
> > error and it stops processing the code.
> >
> > I tried to figure out how to test the subform and the form for a record
> > and
> > then use the delete command, but have be unsuccessful at that.
> >
> > Help would greatly be appreciated.
> >
> > TIA,
> > :Brandon:
>
>

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net