S
Sandy
Hello
I have a tab control on a form that displays records selected from a drop
down.
The On Change for the Tab Control is
Private Sub TabCtl0_Change()
DoCmd.Requery
End Sub
Which works fine.
However, if a user clicks one of the tab/page and then clicks the SAME
tab/page (ie the one that is already selected) again, the currently selected
record is lost and the form defaults back to the first record in the
underlying table when they click over to another tab/page. It seems to be
running the OnChange event again even though the page is not changing.
How do I prevent this from happening?
Someone on the forum suggested I create a
"module-level variable in your form's module that keeps track of the current
tab - when the form is open set it to the tab number that is displayed when
the form is open. Then, in the On CHange event, check to see if the new tab
number value is the same as the previous one. If so, this means you're still
on the same tab, so do nothing, otherwise reset the variable to the new tab
number that was selected and do your requery.
This sounds like a good idea but I am not sure how to go about it.
Do I create the module in the same code window that is used for the main
form, or a separate module in the modules objects?
Here is an idea of what I think I need to do:
``````````````````
dim PageNum As Integer
pageNum = TabCtl0.Pages.Item(#PageNum#)
not sure how to get the #PageNum# into the PageNum variable?
``````````````````
Then for the OnChange Event on the TabControl:
``````````````````
Private Sub TabCtl0_Change()
dim PageNum As Integer
if PageNum <> TabCtl0.Pages.Item(PageNum) then
DoCmd.Requery
' else do nothing? does this need to be coded in???
end if
End Sub
``````````````````
Sorry for being such a nube
thanks!
s
I have a tab control on a form that displays records selected from a drop
down.
The On Change for the Tab Control is
Private Sub TabCtl0_Change()
DoCmd.Requery
End Sub
Which works fine.
However, if a user clicks one of the tab/page and then clicks the SAME
tab/page (ie the one that is already selected) again, the currently selected
record is lost and the form defaults back to the first record in the
underlying table when they click over to another tab/page. It seems to be
running the OnChange event again even though the page is not changing.
How do I prevent this from happening?
Someone on the forum suggested I create a
"module-level variable in your form's module that keeps track of the current
tab - when the form is open set it to the tab number that is displayed when
the form is open. Then, in the On CHange event, check to see if the new tab
number value is the same as the previous one. If so, this means you're still
on the same tab, so do nothing, otherwise reset the variable to the new tab
number that was selected and do your requery.
This sounds like a good idea but I am not sure how to go about it.
Do I create the module in the same code window that is used for the main
form, or a separate module in the modules objects?
Here is an idea of what I think I need to do:
``````````````````
dim PageNum As Integer
pageNum = TabCtl0.Pages.Item(#PageNum#)
not sure how to get the #PageNum# into the PageNum variable?
``````````````````
Then for the OnChange Event on the TabControl:
``````````````````
Private Sub TabCtl0_Change()
dim PageNum As Integer
if PageNum <> TabCtl0.Pages.Item(PageNum) then
DoCmd.Requery
' else do nothing? does this need to be coded in???
end if
End Sub
``````````````````
Sorry for being such a nube
thanks!
s