[AccessD] Dirty Cancel Clear all controls

B Heygood Accesspro at cox.net
Wed Feb 14 13:04:36 CST 2018


SOLVED

What a novel idea, delete all those lines of code and start over.
Sometimes we don't see the forest for the code.

Thanks Rocky.
Good to catch up.
See you soon on the coast.

Bob



-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Rocky Smolin
Sent: Wednesday, February 14, 2018 8:27 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

Bob:

Send me your phone number.  Or call me. We haven't talked in a while.

R
760.683.5777

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Bob
Heygood
Sent: Tuesday, February 13, 2018 10:42 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

Rocky,
I am opening a bound form.
On open moves to a new record.
If I cancel (click the cancel button) without making any entries all is
well.
But, if I make an entry and don't manually delete any entered data that
record is saved when canceling.
The idea is to be able to "cancel" any entries and start again at a blank
new record.
There is a potential for someone to read a barcode also, buy just any entry
needs to be deleted.

Thx
Bob


-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Rocky Smolin
Sent: Tuesday, February 13, 2018 7:20 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

Bob:

Not sure why you need to iterate through the bound fields.  Why does Me.Undo
not work?

I NewRecord = True at this point?  Or are you trying to delete all of the
data from an existing record?

Rocky


-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of B
Heygood
Sent: Tuesday, February 13, 2018 5:08 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

Jim,
Yes, null seems to be more appropriate. I made that change.
All of the controls needing clearing at text boxes bound to text fields.
I no longer get an error message when iterating thru the controls now.
But, when the code is ended, the values are still present on the form.....


Thx
Bob


-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Jim
Dettman
Sent: Tuesday, February 13, 2018 12:36 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

Bob,

   A couple things:

  Me.Dirty = False is equivalent to Me.Undo for the record and you will be
back to default values.

 The alternative is Me.Undo, but the catch there is you may need two; one
for the control (if it's dirty) and then one for the record.   Most use
Me.Dirty = False because it covers everything. You only need one or the
other.

 You can't clear controls like this as not everything can be modified (i.e.
an autonumber).   I would either:

1. check the field type it's bound to
2. rely on the enabled field (assuming everything you want cleared is
enabled).
3. Use a tag in the control Tag property if it should be cleared or not.

 With that said though, you usually want new records to be at their
defaults.   If you don't, then maybe you want to clear all the default
values.

 Also instead of a zero length string, you should be setting the control to
Null.

Jim.

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of B
Heygood
Sent: Tuesday, February 13, 2018 1:44 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

I think me.undo is working. But need to clear entries to get to an unsullied
new record.

See on the web that some variable set and checked in the beforeupdate event
might help.....

Private Sub cmdCancel_Click()

 On Error GoTo cmdCancel_Click_Error
 
    If Me.Dirty Then Me.Dirty = False
    'DoCmd.GoToRecord , , acNewRec
     Dim ctlC As Control
        ' For each control.
       For Each ctlC In Me.Controls
           If ctlC.ControlType = acTextBox Then
                ' Clear New Value.  THIS IS WHERE THE ERROR HAPPENS ON THE
CONTROL FOR THE PRIMARY KEY ++++
               ctlC.Value = ""             '        Me.txtEquipID
           End If
        Next ctlC
   Me.Undo
   
    Me.txtEquipID.SetFocus
    

   On Error GoTo 0
   Exit Sub

Bob



-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of
Rocky Smolin
Sent: Tuesday, February 13, 2018 10:30 AM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Dirty Cancel Clear all controls

Try Me.Undo

r

-----Original Message-----
From: AccessD [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Bob
Heygood
Sent: Tuesday, February 13, 2018 10:03 AM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Dirty Cancel Clear all controls

Hello to the list,
I am looking to allow my user to bail and trash all info entered and not
save the record. And goto a new record.
Have a button "Cancel".
I have used the isdirty and the cancel methods of the form.
Somehow not getting it done.

Maybe the order in which I am attempting ??


A 2010 W 8.1

Tia
Bob


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com



More information about the AccessD mailing list