Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 02-19-2018, 03:41 AM   #1
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Error handling docmd.runcommand

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.
Attached Files
File Type: accdb Database2.accdb (832.0 KB, 31 views)

helmerr is offline   Reply With Quote
Old 02-19-2018, 04:18 AM   #2
Ranman256
Newly Registered User
 
Join Date: Apr 2015
Location: KY,USA
Posts: 3,378
Thanks: 0
Thanked 747 Times in 732 Posts
Ranman256 will become famous soon enough Ranman256 will become famous soon enough
Re: Error handling docmd.runcommand

you really shouldnt program for UNDO. Its something the user does when they make a mistake.
Ranman256 is offline   Reply With Quote
Old 02-19-2018, 04:30 AM   #3
JHB
Have been here a while
 
Join Date: Jun 2012
Location: In the south of Denmark (Jutland), near the German border.
Posts: 7,720
Thanks: 3
Thanked 2,082 Times in 2,037 Posts
JHB has a spectacular aura about JHB has a spectacular aura about
Re: Error handling docmd.runcommand

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

__________________
If the above post has helped you, why not take the time to say thank you, by pressing the "Thumbs up."
JHB is offline   Reply With Quote
Old 02-19-2018, 04:44 AM   #4
moke123
Me.Dirty=True
 
moke123's Avatar
 
Join Date: Jan 2013
Location: Massachusetts
Posts: 797
Thanks: 3
Thanked 238 Times in 224 Posts
moke123 will become famous soon enough
Re: Error handling docmd.runcommand

Quote:
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 ...
moke123 is offline   Reply With Quote
The Following User Says Thank You to moke123 For This Useful Post:
helmerr (02-19-2018)
Old 02-19-2018, 04:05 PM   #5
helmerr
Newly Registered User
 
Join Date: Nov 2013
Posts: 140
Thanks: 33
Thanked 0 Times in 0 Posts
helmerr is on a distinguished road
Re: Error handling docmd.runcommand

Thank you all for your comments and suggestions. I don't know why I couldn't figure this out yesterday..

helmerr is offline   Reply With Quote
Reply

Tags
docmd , error , reset , undo

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
3624 error when using DoCmd.RunCommand acCmdSaveRecord. Help? Lili1964 Modules & VBA 0 05-08-2013 08:28 AM
Error returned with use of DoCmd.RunCommand acCmdSaveRecord dbaldwin Modules & VBA 3 04-01-2011 10:06 AM
Error Handling - Docmd.RunSQL AccessNub Forms 3 11-19-2007 10:08 AM
docmd.runcommand.accmdSaveRecord nuttychick Modules & VBA 11 07-04-2004 11:20 PM




All times are GMT -8. The time now is 01:05 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World