How to stop update to database when moving among tabs in TabControl (1 Viewer)

path479

Registered User.
Local time
Today, 19:57
Joined
Jan 4, 2016
Messages
22
I have a form "Customer Details" with a tab control. The header information in this form is from the Customer table

The tab control has 3 tabs.
- The 1st and 3rd tabs are also displaying information from the Customer table.
- The 2nd tab "Orders" consists of subform "Order Listing". Data is from the Orders table.

When changes have been made to any of the fields in the header, 1st tab or 3rd tab AND move among these three sections, none of the changes are updated to the Customer table until the Save button is clicked. This is working as intend.

However if one make the changes and click onto the 2nd tab, all the changes are committed to the database. Is there anyway to catch this and stop the update in the database? We want the user to use the Save button to commit changes made. We also have a Cancel button to undo any changes made on the form.

I have tried using MessageBox to display the values in the OnClick event in both the Tab Control and at the page tab level. However it seems the data has been committed even before the OnClick event.
 

JHB

Have been here a while
Local time
Today, 11:57
Joined
Jun 17, 2012
Messages
7,732
..
However if one make the changes and click onto the 2nd tab, all the changes are committed to the database. Is there anyway to catch this and stop the update in the database? We want the user to use the Save button to commit changes made. ..
The made the controls unbound and use some code to load the value for them on form load event, and some code to write the changes to the table when the button is pressed.
Or use some kind of a temporary table and some code.
As long as you stay in the same record the changes isn't written to the table, but when the focus moves away from that record then the table get updated, I think that is what happen when the 2nd tab is chosen.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:57
Joined
Feb 19, 2013
Messages
16,607
As long as you stay in the same record the changes isn't written to the table, but when the focus moves away from that record then the table get updated
I agree - I suspect your second tab has a subform on it and it is moving to the subform that is causing the problem
 

path479

Registered User.
Local time
Today, 19:57
Joined
Jan 4, 2016
Messages
22
Sorry. Thank you for pointing it out. I am new to using any form of forum and don't really know what the etiquette is. Will ensure there are no duplicate post in future.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 10:57
Joined
Feb 19, 2013
Messages
16,607
no problem with duplicate posts, just explain why you have done it and provide the links so others can see if their thoughts have already been covered.

re subform on tab, then as JHB has suggested, when you move to the subform, the main form gets updated. Usually a subform recordsource is a child table to the mainform recordsource - and a child can't exist without a parent, so the mainform needs to be saved to create the parent record before the child record(s) can be created

the only way round it is to make the forms controls unbound, but this then involves a lot of extra coding to assign values in controls to the appropriate fields in the table. It is a big subject so google 'access unbound forms' to find out more.

There is also a technique using the 'begintrans' and 'committrans' methods which may be of help - again google to find out more, it may be appropriate for your situation
 

path479

Registered User.
Local time
Today, 19:57
Joined
Jan 4, 2016
Messages
22
Hi CJ_London. Thank you for the all advice. I am inclining to leave the subform as is for now and, if time permits, I will look into making it unbound.

Is there anyway to have a messagebox whenever users click the 2nd tab so to let them know changes made in the other tabs have been saved?

I have tried adding messagebox for On Click event on the page for the 2nd tab but it doesn't work. No messagebox at all. And if I add the messagebox for On Click event on the tab control, the message will get displayed regardless which tab is clicked.
 

sneuberg

AWF VIP
Local time
Today, 02:57
Joined
Oct 17, 2014
Messages
3,506
You could put the message box in either the main forms before update or after update, but that would result in a message when they clicked Save too, so I think the subforms On Enter event would be the best bet.
 
Last edited:

JHB

Have been here a while
Local time
Today, 11:57
Joined
Jun 17, 2012
Messages
7,732
..
I have tried adding messagebox for On Click event on the page for the 2nd tab but it doesn't work. No messagebox at all. And if I add the messagebox for On Click event on the tab control, the message will get displayed regardless which tab is clicked.
You could use the tabcontrol's on change event and some If structure to determine which page is clicked - Me.YourTabControlName gives your the page index.
 

path479

Registered User.
Local time
Today, 19:57
Joined
Jan 4, 2016
Messages
22
Thank you Uncle_Gizmo. The link and the sample database are very helpful!
 

Users who are viewing this thread

Top Bottom