Solved

OnChange Event of subform with tab control

Posted on 2013-05-10
10
817 Views
Last Modified: 2013-05-11
I am trying to create a message box on a subform with tab control prior to moving to the next tab in Access 2003. Basically it asks if they have saved their information. I have put the vba on the change event of the form. What happens is that the message box appears before the subform has loaded.

Dim Qres As Integer
If Qres = vbYes Then
Me.TabCtl40.Pages(intNextPage).SetFocus
Else
Me.TabCtl40.Pages(x).SetFocus
End If
Should I be placing this somewhere else on the form?
Thanks for the help.
0
Comment
Question by:smolbeck367
  • 6
  • 4
10 Comments
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39157100
Hi,

What sets the value of Qres?  What sets x?

Regards,

Bill
0
 

Author Comment

by:smolbeck367
ID: 39157374
I declare Qres as the variable for the response to the yes/no message box. I use x to move through the pages.
Dim x as integer
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39157574
Hi,

Where is the message box code?  Where is the code above in the form?  There is not enough info to determine the issue or to see what's happening from the code above.

Please post a sample db if possible and I'll try to help further.

Regards,

Bill
0
 

Author Comment

by:smolbeck367
ID: 39158112
Good morning Bill. I appreciate the help.
This is what i have for code on the tabchange event.

Dim x As Integer
Dim Qres As Integer
Dim intCurrPage As Integer
Dim intNextPage As Integer

x = Me.TabCtl40.Value

'Qres = MsgBox("Have you remembered to save your updates?", vbYesNo, "Save records")

Me.txtDate = Right(Me.TabCtl40.Pages(x).Caption, 10)
'If Qres = vbYes Then
'Me.TabCtl40.Pages(intNextPage).SetFocus
'Else
'Me.TabCtl40.Pages(x).SetFocus
'End If

End Sub

My goal is that they cannot move to the next tab until they have saved the current on. i have not done much with forms with tabs.
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39158225
Hi,

What is the recordsource of the form?  If the form is a bound form then you can check to see if there are uncommitted changes by checking/setting the forms dirty property.

If me.dirty=true then
  me.dirty = false
endif

You could prompt them to save by changing the code - but why?

The above code will save the record.  

Regards,

Bill
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 14

Expert Comment

by:Bill Ross
ID: 39158227
Continued...

The tab control behaves just like any other control excepts it holds other controls.  If you want changes to be saved between tab changes then just execute the save in the tabs OnChange event which occurs when the user changes tabs.

Regards,

Bill
0
 

Author Comment

by:smolbeck367
ID: 39158229
I will give that a try. Thanks again for the help.
0
 
LVL 14

Accepted Solution

by:
Bill Ross earned 500 total points
ID: 39158242
Ok.  Put the code in the tab control onchange event...

If me.dirty=true then
  me.dirty = false
endif
0
 

Author Closing Comment

by:smolbeck367
ID: 39158587
Thanks for your help.
0
 
LVL 14

Expert Comment

by:Bill Ross
ID: 39158606
Glad to help anytime.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now