Error handling docmd.runcommand (1 Viewer)

foshizzle

Registered User.
Local time
Today, 08:55
Joined
Nov 27, 2013
Messages
277
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

  • Database2.accdb
    832 KB · Views: 92

Ranman256

Well-known member
Local time
Today, 08:55
Joined
Apr 9, 2015
Messages
4,339
you really shouldnt program for UNDO. Its something the user does when they make a mistake.
 

JHB

Have been here a while
Local time
Today, 13:55
Joined
Jun 17, 2012
Messages
7,732
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
Local time
Today, 08:55
Joined
Jan 11, 2013
Messages
3,849
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 ...
 

foshizzle

Registered User.
Local time
Today, 08:55
Joined
Nov 27, 2013
Messages
277
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

Top Bottom