Select case

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want my user to stay on the tab they are on if conditions are met. When
they click off to another tab, I want a message and return to the tab they
were/are on. I get everything working but the return. If I remove my
conditions test and set focus to another tab other than the resident one, the
focus changes. I need to stay on that original tab until conditions are met.

I have this code in the tabControl change event.

Select Case Me.tabControlMain
Case 0
If something Then
response something
Me.tab0.SetFocus
End If
Case 1 ...etc.
End Select

Can someone help me understand?
 
Chris

Would something like this work?

If Me!tabControlName.Value <> 0 Then
Me!tabControlName.Value = 0
End If

This would force the user back to the first tab, no matter which tab they
clicked. (This does make me wonder why you bother having any other tabs,
though <g>!)

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Another approach might be to set your tabctl style to none. You still have
the pages, but they aren't visible. Then add a command button for "next"
page and set the button. enabled= false until your page is completed. If
you want the user to be able to move back and forth between the pages, then
you will need another cmd button for "previous".

HTH
Damon
 
1) I'm not sure SetFocus is what you want. Simply setting the value of the
tab control should change the 'active' tab.

2) When the tab_Change event fires the user is already on the "new" page. If
you want to return them to where they were, you need to have stored that
value beforehand.


in the Tab_Change event:

Static iCurrentTab as integer

If SomeCondition then
'Return user to previous tab (i.e., stay where they are)
me.mytab = iCurrentTab
Else
'Condition was not met, allow user to change tabs. Store the "new" tab
value.
iCurrentTab = Me.MyTab
End If

Note that when the form loads, iCurrentTab will be zero until SomeCondition
has not been met the 1st time. If this is undesirable, then rather than
making it a static procedure-level variable, you could make it a
module-level variable and set it to some other "default" value within
Form_Load.

HTH,
 
Thanks Jeff. I must not have been clear.

The user is on tab3 and clicks on tab5.

The user has not met conditions I set for leaving tab3. By clicking tab5
focus changes to tab5.

I want the user to stay or return to tab3 until conditions are met.

Your code works only (I think) to keep the user on tab0 from any other tab.
I don't see how to stay/return when there are 8 tabs for the user to select
from. They must finish work on a given tab before moving. Normally, they
use a command button that tests for completion, allowing them to move to next
task.

How do I do keep them on a tab failing conditions test. (The test is not an
issue.) I want them to stay or return there until the conditions are met.
--
Thanks for your help,
Chris


Jeff Boyce said:
Chris

Would something like this work?

If Me!tabControlName.Value <> 0 Then
Me!tabControlName.Value = 0
End If

This would force the user back to the first tab, no matter which tab they
clicked. (This does make me wonder why you bother having any other tabs,
though <g>!)

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Addendum, per another post within thread:

Keep in mind that when Tab_Change fires the TabControl value already
reflects the "new" tab number. Access doesn't know or care where the user
just was.

So if the user is on tab 3, and clicks on another tab, you need to have
stored the 3 in order to run the test for it as well as return the user to
it.

Module level:
Dim mCurrentTab as Integer

in Form Load:
'Set default tab page, and move user to it
mCurrentTab = 3
MyTab = mCurrentTab

in Tab_Change:

'Run Test for where user *WAS*, not where they just moved to:
Select case mCurrentTab
'More Cases

Case 3
If SomeCondition Then
'Condition met. Move user back to 3
MyTab = mCurrentTab
Else
' Condition Failed. Accept tab change and store new value.
mCurrentTab = MyTab
End If

'More Cases
'Case Else
End Select







George Nicholson said:
1) I'm not sure SetFocus is what you want. Simply setting the value of the
tab control should change the 'active' tab.

2) When the tab_Change event fires the user is already on the "new" page.
If you want to return them to where they were, you need to have stored
that value beforehand.


in the Tab_Change event:

Static iCurrentTab as integer

If SomeCondition then
'Return user to previous tab (i.e., stay where they are)
me.mytab = iCurrentTab
Else
'Condition was not met, allow user to change tabs. Store the "new" tab
value.
iCurrentTab = Me.MyTab
End If

Note that when the form loads, iCurrentTab will be zero until
SomeCondition has not been met the 1st time. If this is undesirable, then
rather than making it a static procedure-level variable, you could make it
a module-level variable and set it to some other "default" value within
Form_Load.

HTH,
 
Thanks again...but I'm confused. Consider that I am very much an amateur.

What I am using now results in desired tab retention, but the message
repeats -- occurs twice. Otherwise, just what I want.

Is there a simple solution?

My code:

'tests for edit/add status
If Me.txtUpdating = 1 Or Me.txtAdding = 1 Then
'Return user to previous tab (i.e., stay where they are)
Me.tabControlMisc = iCurrentTab
response = MsgBox(msg, style, title)
Else
'move to selected tab
iCurrentTab = Me.tabControlMisc
End If
--
Thanks for your help,
Chris


George Nicholson said:
Addendum, per another post within thread:

Keep in mind that when Tab_Change fires the TabControl value already
reflects the "new" tab number. Access doesn't know or care where the user
just was.

So if the user is on tab 3, and clicks on another tab, you need to have
stored the 3 in order to run the test for it as well as return the user to
it.

Module level:
Dim mCurrentTab as Integer

in Form Load:
'Set default tab page, and move user to it
mCurrentTab = 3
MyTab = mCurrentTab

in Tab_Change:

'Run Test for where user *WAS*, not where they just moved to:
Select case mCurrentTab
'More Cases

Case 3
If SomeCondition Then
'Condition met. Move user back to 3
MyTab = mCurrentTab
Else
' Condition Failed. Accept tab change and store new value.
mCurrentTab = MyTab
End If

'More Cases
'Case Else
End Select
 
The message occurs twice because the Change event is happening twice. Once
when the user clicks another tab and once when you send the user back via
code. Since we only want to react to the first instance, try this:

If Me.txtUpdating = 1 Or Me.txtAdding = 1 Then
If Me.tabControlMisc <> iCurrentTab
'Return user to previous tab (i.e., stay where they are)
Me.tabControlMisc = iCurrentTab
response = MsgBox(msg, style, title)
End If
Else
'move to selected tab
iCurrentTab = Me.tabControlMisc
End If

HTH,
 
Back
Top