473,324 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Clear form on exit without table updates

19
Hi, I had this on a prior post and still have some difficulty trying to make it work and the issue might just be very simple. I have a form with multiple tabs on it and each one contains a subform that will update fields in a different table. I have the cycle property on each subform on each tab set to "Current Page" so that there is no more than one record generated per tab and that works fine. The problem I have is if the user will "x" off or closes the form the incomplete record is written to the tables and I only want an update to occur if the user clicks the save button. I coded the on close event in the main and subform properties with the following but it does not stop the update:

Private Sub Form_Close()
Call Me.Undo
End Sub

Any help would be much appreciated.

Thanks Mark.
Feb 27 '07 #1
3 5095
ADezii
8,834 Expert 8TB
Hi, I had this on a prior post and still have some difficulty trying to make it work and the issue might just be very simple. I have a form with multiple tabs on it and each one contains a subform that will update fields in a different table. I have the cycle property on each subform on each tab set to "Current Page" so that there is no more than one record generated per tab and that works fine. The problem I have is if the user will "x" off or closes the form the incomplete record is written to the tables and I only want an update to occur if the user clicks the save button. I coded the on close event in the main and subform properties with the following but it does not stop the update:

Private Sub Form_Close()
Call Me.Undo
End Sub

Any help would be much appreciated.

Thanks Mark.
Declare a Private Variable in your Sub-Form's Declarations. This Variable will only allow the Record to be saved in the Save Command Button:
Expand|Select|Wrap|Line Numbers
  1. Private blnRecordSaved As Boolean
In your Form's BeforeUpdate() Event:
Expand|Select|Wrap|Line Numbers
  1. If blnRecordSaved = False Then Cancel = True
In the Click() Event of the Save Record Button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSaveRecord_Click()
  2. On Error GoTo Err_cmdSaveRecord_Click
  3.  
  4.   blnRecordSaved = True     'needed to Save Record
  5.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  6.   blnRecordSaved = False    'Reset
  7.  
  8. Exit_cmdSaveRecord_Click:
  9.     Exit Sub
  10.  
  11. Err_cmdSaveRecord_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_cmdSaveRecord_Click
  14. End Sub
Since the Click() Event of the Save Record Button is the only location where blnRecordSaved = True, it is the only means by which the Record can be saved.
Mar 1 '07 #2
mtrcct
19
Declare a Private Variable in your Sub-Form's Declarations. This Variable will only allow the Record to be saved in the Save Command Button:
Expand|Select|Wrap|Line Numbers
  1. Private blnRecordSaved As Boolean
In your Form's BeforeUpdate() Event:
Expand|Select|Wrap|Line Numbers
  1. If blnRecordSaved = False Then Cancel = True
In the Click() Event of the Save Record Button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdSaveRecord_Click()
  2. On Error GoTo Err_cmdSaveRecord_Click
  3.  
  4.   blnRecordSaved = True     'needed to Save Record
  5.   DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
  6.   blnRecordSaved = False    'Reset
  7.  
  8. Exit_cmdSaveRecord_Click:
  9.     Exit Sub
  10.  
  11. Err_cmdSaveRecord_Click:
  12.     MsgBox Err.Description
  13.     Resume Exit_cmdSaveRecord_Click
  14. End Sub
Since the Click() Event of the Save Record Button is the only location where blnRecordSaved = True, it is the only means by which the Record can be saved.

Many thanks, I will give it a try and let you know the outcome.
Mar 1 '07 #3
NeoPa
32,556 Expert Mod 16PB
Alternatively, if there are easily tested criteria already in your data (controls that must be filled in), you could do that check in your BeforeUpdate event procedure and get away without creating the extra control (the button).
If that's not clear, I'm talking about testing a control (or multiple controls) to see if it's (they're) set before allowing the update to progress.
Mar 1 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
15
by: simonmarkjones | last post by:
I want to validate my form using a BeforeUpdate event. However now that i call my code with a beforeupdate it wont let me go to next or previous records. What code should i put in o allow me...
6
by: Shyguy | last post by:
I have a form where one of the entries is "Contact". On BeforeUpdate I check the table for the existance of that Contact. A mesage box informs the user that the name is already in the table and...
21
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each...
6
by: jpatchak | last post by:
Hello, I have a main form with one subform. I have a command button on the main form to delete the current record. Below is my code. The tables on which the main form and subform are based...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
7
by: mtrcct | last post by:
Hi, I have been playing around with various forms and have asked some previous questions on this topic, but thought it best to start a new thread since my forms structes have changed if anyone can...
10
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some...
13
JodiPhillips
by: JodiPhillips | last post by:
G'day, I have a silly and simple problem that I need some guidance with. Due to the way our network is set up, I am unable to use the group permissions for Access and have had to implement log...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.