Solved

OnChange Event of subform with tab control

Posted on 2013-05-10
10
815 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

708 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