Code works on a button, but not on a tab?...

E

efandango

I have some VBA code that works fine on a form button on 'TestForm' (within
the tab page in question), but when i paste the code into the 'On Click'
action of the tab; nothing happens. I get no error message, and the code
doesn't do the job. Is there a limitation for tabs?. Nothing changes; it's as
if the tab had never been clicked.

The Form Structure is:

Testform
frm_Points_Test_A
frm_Points_Test_B
frm_Points_Test_C


My Code for the button: (It's essentially 3 almost identical routines for
resetting 3 forms on another form within the tab page):

Private Sub Points_test_Click()

stDocName = "QRY_Delete_PointsTest_A"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_A"
DoCmd.SetWarnings True 'enable warnings
[frm_Points_Test_A].Requery
[frm_Points_Test_A].Form![Combo_Answer_A].Requery
[frm_Points_Test_A].Form![Combo_Answer_A] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"

stDocName = "QRY_Delete_PointsTest_B"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_B"
DoCmd.SetWarnings True 'enable warnings
[frm_Points_Test_B].Requery
[frm_Points_Test_B].Form![Combo_Answer_B].Requery
[frm_Points_Test_B].Form![Combo_Answer_B] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"

stDocName = "QRY_Delete_PointsTest_C"
DoCmd.OpenQuery stDocName, acNormal, acEdit
DoCmd.SetWarnings False 'disable warnings
DoCmd.OpenQuery "QRY_Append_PointsTest_C"
DoCmd.SetWarnings True 'enable warnings
[frm_Points_Test_C].Requery
[frm_Points_Test_C].Form![Combo_Answer_C].Requery
[frm_Points_Test_C].Form![Combo_Answer_C] = "?"
'DoCmd.OpenQuery "QX_Score_Points_Sub_A"

End Sub
 
D

Dirk Goldgar

efandango said:
I have some VBA code that works fine on a form button on 'TestForm'
(within the tab page in question), but when i paste the code into the
'On Click' action of the tab; nothing happens. I get no error
message, and the code doesn't do the job. Is there a limitation for
tabs?. Nothing changes; it's as if the tab had never been clicked.

The Click event of a tab control doesn't fire when most people would
expect it to fire, and is of very limited use. It does *not* fire when
the user clicks on one of the page tabs -- which is what people usually
expect -- and it doesn't fire when you click the body of a tab page,
either (though the Click event of the *page* does fire then). The tab
control's Click event fires only when you click on the border of the tab
control. Not much use, is it?

If you want to do something when the user changes from one tab to
another, use the tab control's Change event. And, in case you didn't
know it, the value of the tab control itself is the PageIndex of the
current tab page. In the tab control's Change event, that's the new
page, not the former page.
 
E

efandango

Dirk,

Thanks for that, I thought i was doing somethig wrong with the code. I
managed to get my code to work on the page in question by pasting it into the
change event of the 'master' tab control. The question is though, how do i
get it to fire when i just click that particular tab page, as it seems to
fire no matter what tab i click?... I wasn't entirely sure how to find out a
tab PageIndex.

regards

Eric
 
R

Rick Brandt

efandango said:
Dirk,

Thanks for that, I thought i was doing somethig wrong with the code. I
managed to get my code to work on the page in question by pasting it
into the change event of the 'master' tab control. The question is
though, how do i get it to fire when i just click that particular tab
page, as it seems to fire no matter what tab i click?... I wasn't
entirely sure how to find out a tab PageIndex.

The Value property of the TabControl will correspond to the selected TabPage (0
for the first page, 1 for the second, etc.). Just test the Value property in
your code with an If-Then block or a Select Case block and you can then easiliy
decide what code to run per-page selected.
 
D

Dirk Goldgar

Rick Brandt said:
The Value property of the TabControl will correspond to the selected
TabPage (0 for the first page, 1 for the second, etc.). Just test
the Value property in your code with an If-Then block or a Select
Case block and you can then easiliy decide what code to run per-page
selected.

What Rick said.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top