 |
 |

11-08-2003, 01:54 PM
|
|
Newcomer
|
|
Join Date: Nov 2003
Posts: 3
|
|
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
|
|

11-10-2003, 02:11 AM
|
 |
Senior Contributor
|
|
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
|
|
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.
|
|

11-10-2003, 02:13 AM
|
 |
Senior Contributor
|
|
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
|
|
|
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.
|
|

11-10-2003, 02:49 PM
|
|
Newcomer
|
|
Join Date: Nov 2003
Posts: 3
|
|
|
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
|
|

11-11-2003, 02:22 AM
|
 |
Senior Contributor
|
|
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
|
|
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.
|
|

11-12-2003, 05:56 AM
|
|
Newcomer
|
|
Join Date: Nov 2003
Posts: 3
|
|
Thank You
|
Paul,
Thank You So Much For Your Clear Explanation....It helps a lot...
Linhsy
|
|

11-12-2003, 06:01 AM
|
 |
Senior Contributor
|
|
Join Date: Apr 2002
Location: glbTheWorld.Europe.UK
Posts: 1,201
|
|
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!
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|