Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > Undo Problems On Subforms


Reply
 
Thread Tools Display Modes
  #1  
Old 11-08-2003, 01:54 PM
LINHSY LINHSY is offline
Newcomer
 
Join Date: Nov 2003
Posts: 3
Post Undo Problems On Subforms


Need Your Help, I have One Main form (FrmClient) which includes two subform(sFrmService and sFrmProduct). They are all Bounded Forms. The Form layout looks as follow: some fields of FrmClient, Then sFrmService, sFrmProduct, and finally followed by one field (txtFurtureService) of FrmClient. They are in One-to-Many Relationships. I did enforce the integrity relationship. I create Exit Button on Main Form. I want before Exiting it will Check if user makes any changes to Three Forms, And Ask the user if he/she want to save the changes or not? If Not, I will Undo the changes. I Tried to write code as follow:

Private Sub cmdExit2_Click()
On Error GoTo Err_cmdExit2_Click


If Me.Dirty = True Or bProductStatus = True Or bServiceStatus = True Then

Dim lResponse As Long
lResponse = MsgBox("Do You Want to Save Changes Before Exit?", vbYesNo, "Exit Comfirmation")
If lResponse = vbNo Then

Me.Undo
Me.sFrmProduct.Form.Undo 'Not Sure syntax is correct
Me.Service.Form.Undo 'Not Sure syntax is correct
End If
End If
DoCmd.Close

Exit_cmdExit2_Click:
Exit Sub

Err_cmdExit2_Click:
MsgBox Err.Description
Resume Exit_cmdExit2_Click

End Sub

3 Testing Cases:
1. If I only enter data on Main Form, Then It does the job.
2. However, If I enter in the main Form, and then the subforms, It does undo anything, even the main Form.
3.If I enter the main form, then subforms, and finally to the last field(txtFutureService) of Main Form..., Then it only undo the txtFutureService...The rest they still saving.

Would you please Help...

You can email me at lihoang2003@yahoo.com...Thanks ahead.

Linhsy
Reply With Quote
  #2  
Old 11-10-2003, 02:11 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Hi Linhsy,


Instead of using Undo, try:
Code:
SendKeys "{ESC}{ESC}", True
It's basically the same, except it aborts any changes made to the current record.


Paul.
Reply With Quote
  #3  
Old 11-10-2003, 02:13 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Sorry,

Just to add to the last reply, there, you need to put the code into each form (subs and main) in the Before Update event.


Paul.
Reply With Quote
  #4  
Old 11-10-2003, 02:49 PM
LINHSY LINHSY is offline
Newcomer
 
Join Date: Nov 2003
Posts: 3
Question

Hi Paul, Thank You for Your help...

If I do as your way..(before update event) then everytime I leave the mainform or subforms, it is automatic undo. Unfortunately, That is not what I want. Here are what supposed to happen:

After made any modification to MainForm or Subform, User may click "Exit" button on the MainForm...Then it will generate a Yes/No MessageBox to ask whether user want to save the changes..

a. If User say Yes...then It go ahead and Exit the Form (Since they are all Bounded Forms, all the data will be saved automatically.

b. If User say NO...Then it will Undo any changes User have made.


Paul, any further suggestion for this problem.

Thanks! again Paul...I'm really apprieciated your help...


Linhsy
Reply With Quote
  #5  
Old 11-11-2003, 02:22 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

Hi Linhsy,


The event will fire for each record that is saved. I can't see the reasoning behind having this feature for just the one record when the form exits.

As for it being an automatic undo, then all you need to do is enclose the SendKeys in an If statement...
Code:
If MsgBox("Do you want to save this record?", vbQuestion, "Save") = vbNo Then SendKeys "{ESC}{ESC}", True End If

Paul.
Reply With Quote
  #6  
Old 11-12-2003, 05:56 AM
LINHSY LINHSY is offline
Newcomer
 
Join Date: Nov 2003
Posts: 3
Default Thank You

Paul,


Thank You So Much For Your Clear Explanation....It helps a lot...


Linhsy
Reply With Quote
  #7  
Old 11-12-2003, 06:01 AM
Mandelbrot's Avatar
Mandelbrot Mandelbrot is offline
Senior Contributor
 
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
Default

No Probs, Linhsy -

All you've got to do is ask, and if I can;t help, there's deffinately someone in the forum who can!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to undo subform after editing the previous or adding subform record???? elleetan Word, PowerPoint, Outlook, and Other Office Products 1 09-16-2003 08:17 AM
undo help!! everlasting General 5 06-22-2003 06:44 PM
I'm having a few problems - Please help Honey_Bear General 7 06-08-2003 10:07 PM
Undo/ Redo for Level Editor Jdo300 General 2 08-02-2002 09:24 PM
Code for Undo in Word VBA simonsays Word, PowerPoint, Outlook, and Other Office Products 2 05-27-2002 11:15 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->