Error handling docmd.runcommand (1 Viewer)

helmerr

Registered User
Joined
Nov 27, 2013
Messages
140
I'm attaching a sample of a database I've been having some minor issues with. While the form and buttons work, I'd like to work out one final bug:

The sample DB consists of three forms: one main form and two subs; one of which is continuous. Both forms use bound text and comboboxes.

The combination of forms is used to add new records from the top form (frmStaffMXHeader), as well as edit existing records from the continuous form (frmStaffMXDetail) by selecting any record from the continuous form in the detail section. When records are selected from the detail/continuous form, they are populated to the top form for editing using some bookmark code.

When the user clicks the cmdReset icon (or cmdNew), the commands docmd.runcommand acCmdUndo and acNewRec are run in order to clear the top form and prepare it for a new record entry, which is also the default when the form loads.

The issue I'm having is when the user clicks cmdReset, prior to any data being entered in the blank new record, it triggers the error below. Please note, I've tried using IF statements to check and only run if the textbox controls have been entered prior to clicking this button, as well as checking for me.dirty but I have been unsuccessful. (Perhaps something was wrong with my code). For icing on the cake, if Its possible to undo all controls at once in the header form, that'd be perfect. Please help, thank you.

Run-time error '2046'
The command or action 'Undo' isn't available now.
 

Attachments

Ranman256

Registered User
Joined
Apr 9, 2015
Messages
3,435
you really shouldnt program for UNDO. Its something the user does when they make a mistake.
 

JHB

Have been here a while
Joined
Jun 17, 2012
Messages
7,720
You need to set the focus to a control there can be undone, (a button can't be undone).
Ex:
Code:
    Me.txtEmpID.SetFocus
    DoCmd.RunCommand acCmdUndo  ' Clear controls of any input
 

moke123

AWF VIP
Joined
Jan 11, 2013
Messages
1,079
The issue I'm having is when the user clicks cmdReset, prior to any data being entered in the blank new record, it triggers the error below.
You cant undo a form that hasn't been dirtied. You are testing for any null field which will always be true if no data has been entered.

You could try testing for dirty
If me.Dirty = True then me.undo ...
 

helmerr

Registered User
Joined
Nov 27, 2013
Messages
140
Thank you all for your comments and suggestions. I don't know why I couldn't figure this out yesterday..
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom