Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undo command

Status
Not open for further replies.

reta

Technical User
Dec 23, 2004
51
AU
Hi
I was wondering does anyone know how to undo a record from a different form.
For example when the user goes back to the main menu, multiple forms will close and if the user has inputted any data it will undo the record. Therefore, when they press the back to main button, only once, all the forms will close and the undo command will undo any records entered.
Thanks
I hope that makes sense.
Reta
 
How are ya reta . . . . .

Bearing in mind:
[ol][li]When you navigate from the currently edited record to any other record (including new), [blue]the currently edited record is automatically saved.[/blue][/li]
[li]Without any other intervention, [blue]closing a form automatically saves the currently edited record.[/blue][/li][/ol]
The point being . . . [purple]you can only undo a record if its in edit mode.[/purple] So the effectiveness of your undo in all open forms is dependent on the user leaving the record in edit mode, or, [blue]not navigating to another record![/blue] If they do, the undo for that form will be ineffective.

The following code works on the premise that when all other forms are closed, the mainform is the only one open! So in a [blue]module[/blue] in the [blue]modules window[/blue], copy/paste the following routine ([blue]You![/blue] substitute proper names in [purple]purple[/purple]):
Code:
[blue]Public Sub AllFormsUndo()
   Dim x As Integer
   
   Do Until Forms.Count = 1
      If Forms(0).Name = "[purple][b]MainFormName[/b][/purple]" Then x = 1
      Forms(x).Undo
      DoCmd.Close acForm, Forms(x).Name
      x = 0
   Loop
      
End Sub[/blue]

[purple]Call the routine from anywhere you like![/purple]

Calvin.gif
See Ya! . . . . . .
 
reta . . . . .

Slight modification incase no forms are open when the code is run:
Code:
[blue]Public Sub AllFormsUndo()
   Dim x As Integer
   
   Do Until Forms.Count [b]< 2[/b]
      If Forms(0).Name = "[purple][b]MainFormName[/b][/purple]" Then x = 1
      Forms(x).Undo
      DoCmd.Close acForm, Forms(x).Name
      x = 0
   Loop
      
End Sub[/blue]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top