Cycle through controls on a tabbed form

K

Karen

I have a tab control on a form. When I click a 'Reset' command button I want to cycle through the controls on the active page and reset them to particular values. I know I can find the current active index with currentindex= Me!TabCtl0.Value. I've tried this code but it doesn't work, I get an error "type mismatch". I know I must not be referring to the controls on the active tab correctly. Any gurus out there that can show me the way?

Dim ctl as Control
Dim intPage as Integer

intPage = Me!TabCtl0.Value

For Each ctl In Me.TabCtl0(intpage) 'error fires on this line
With ctl
Select Case ctl.ControlType
Case acTextBox
MsgBox ("this is a textbox")
End Select
End With
Next ctl

Karen
 
R

Roger Carlson

Unfortunately the Tab control is not a container. All of the controls in the Tab control are actually contained in the Form itself, not the Tab Control. All the tab control does in organize which set of controls is visible.

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org

I have a tab control on a form. When I click a 'Reset' command button I want to cycle through the controls on the active page and reset them to particular values. I know I can find the current active index with currentindex= Me!TabCtl0.Value. I've tried this code but it doesn't work, I get an error "type mismatch". I know I must not be referring to the controls on the active tab correctly. Any gurus out there that can show me the way?

Dim ctl as Control
Dim intPage as Integer

intPage = Me!TabCtl0.Value

For Each ctl In Me.TabCtl0(intpage) 'error fires on this line
With ctl
Select Case ctl.ControlType
Case acTextBox
MsgBox ("this is a textbox")
End Select
End With
Next ctl

Karen
 
D

Dirk Goldgar

Roger Carlson said:
Unfortunately the Tab control is not a container. All of the
controls in the Tab control are actually contained in the Form
itself, not the Tab Control. All the tab control does in organize
which set of controls is visible.

But each page of the tab control has a Controls collection, so you can
write code like this to do what Karen is attempting:

Dim ctl As Control

With Me!TabCtl0
For Each ctl In .Pages(.Value).Controls
Select Case ctl.ControlType
Case acTextBox
MsgBox ctl.Name & " is a textbox"
End Select
Next ctl
End With
 
K

Karen

Dirk,

Thanks again, you've come up with great help for me more than once. This
works perfectly!

Karen
 

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

Top