Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1703
  • Last Modified:

DoCmd.RunCommand acCmdUndo

Hey everyone,

I am using DoCmd.RunCommand acCmdUndo to undo changes in my form if the user hits the cancel button.  It works great for the main form but it does not work for the subform.  How do I undo changes in both the main form and subform on the cancel button?????

Any Ideas,
Itwg
0
itwebguy
Asked:
itwebguy
  • 5
  • 3
  • 3
  • +1
1 Solution
 
PsychoDazeyCommented:
Heres an article you may find useful:
http://support.microsoft.com/default.aspx?scid=kb;en-us;208833
Basically you have to create some type of delete query that deletes the corresponding data in the subform table after the docmd.runcommand line
You may want to set a variable using the main form key field, run the undo action and then run a SQL statement like:
docmd.runsql "DELETE * FROM SubformTable WHERE table.field = " & YourVariable & ";"
0
 
kraigCommented:
Whenever I have a situation like this I find it easiest to have the form's data source be a temporary table.  On cancel, do nothing.  On submit, write the data in the temporary table to the primary table.

Just make sure the temp table is cleared when the form opens.
0
 
itwebguyAuthor Commented:
Yeah,

I wanted to do the temp table thing but my supervisor wanted to just use the undo command.

Itwg - hands tied
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kraigCommented:
I don't think there is an easy solution for un-doing changes to a sub-form.

Instead of a temp table, make the form un-bound and populate the fields when the form opens.

Then on cancel do nothing, and on submit commit the changes.  I've found these types of forms are faster loading on the user end especially when the form is based on a large recordset.

Tell your supervisor that you can use undo and have it not work, or use another method and have it work.
0
 
PsychoDazeyCommented:
If you used the temp table thing how would you deal with multiple records in your subform?  Would you have to run the append query after each time you added a new record to the subform?
0
 
kraigCommented:
Two temp tables.
Just run the query(s) when the form is closed.
0
 
PsychoDazeyCommented:
You can get the undo to work with the article I linked, its just not as straight-forward as you would think.  Thanks Microsoft!
0
 
itwebguyAuthor Commented:
Yeah... I have about five different subforms ...

Does anyone know how to call the undo typing command using VBCode??  I know that works but can I write that function in code or call it?

Itwg
0
 
PsychoDazeyCommented:
If you mean you want to undo what you typed into a control use: me.ControlName.Undo (or Formname.ControlName.undo depending on where you call it from.)
0
 
shanesuebsahakarnCommented:
Issue 2 undo commands - one for the subform's (or each subform's) Form object and one for the main form.
0
 
itwebguyAuthor Commented:
what does the undo command look like for a subform??
Itwg!!
0
 
shanesuebsahakarnCommented:
If you are calling it from the main form, you can do:
Me!MySubformControl.Form.Undo

Make sure MySubformControl is the name of the subform control, not of the subform itself.
0
 
PsychoDazeyCommented:
So you'll have to undo each control individually it looks like.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now