Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting a tab in the TabStrip control 1

Status
Not open for further replies.

DannyLondon

Programmer
Nov 19, 2002
33
GB
Hi Folks

This seems like it should be a simple issue, but I am struggling to find a solution for it.

I have added a tabstrip control to one of my Access forms. Note that this is the tab control with just the tabs, not with pages.

I can't work out how to select a tab using code (eg, to make tab 1 the active tab). It seems the SelectedItem and Value properties are all read only.

Any ideas?

Thanks, Danny



[rockband] [wiggle][wiggle][wiggle]
 
Assuming you are referring to a "MSForms tabstrip" control, I had no problem setting the value in code. Just remember the forms tabs are zero based so to move it to the second page

Private Sub CommandButton1_Click()
Me.TabStrip1.Value = 1
End Sub

Are you referring to a different control?
 
Hi MajP

Thanks for your reply. The code you have entered is exactly what I was expecting to be able to use.

I am using the Forms.TabStrip.1 control. In my form load, I have the simple code:
Code:
Me.tabAdjustment.value = 0

Unfortunately I get the error:
Code:
Run-time error 2101:  The setting you entered isn't valid for this property.

If I try to read the value of this parameter in the debug window, using:
Code:
? Me.tabAdjustment.value

I get the error:
Code:
Run-time error 450:  Wrong number of arguments or invalid property assignment.

It sure has me baffled. Any ideas?

Thanks, Danny



[rockband] [wiggle][wiggle][wiggle]
 
I do not think that is the MSForms tabstrip control. Go to the object browser and check the properties on the control. I show another control tabstrip1 a member of F3Dynamic.userform which is read only. Is that the control you want or need to use?
Do you want an Acess tab control or MSForms tabstrip?
 
I am trying to use the TabStrip control, as I do not want pages or control containers.

I have started a new mdb file with a new form, placing only the Microsoft Forms 2.0 Tabstrip control, and a command button. With the following code, I still get the error.
Code:
Private Sub Command5_Click()
    
    TabStrip3.Value = 1

End Sub


[rockband] [wiggle][wiggle][wiggle]
 
As a work around could you simply use an Access tab control and shrink it down so that you only see the tabs and not the page? I do not have access open on this computer to see how that looks. It is always safer for portability to use Acess controls vice Active X controls.
 
Here is one thought as well. With Active X controls you have a control container and the object within the container. Some properties and methods can be accessed through the control itself other through the object within. An example is a tree view control. A tree view control has a nodes collection with numerous properties and methods, but you can not access this through the control. But to do anything with a tree view you have to work with the nodes. So if on your form the control is named "tvTree" then you need to do something like this.

dim objTree as treeview
dim ndsNode as nodes
set objTree = me.tvTree.object
set ndsNode = objTree.nodes

However this will fail
set ndsNode as me.tvTree.nodes
because the treeview control container does not have a nodes collection only the object within the container. You will get an error that says something like "this object does not support that property or method"

This is somewhat similar to a subform control with a form object within it.

I do not have Access open to test this, but you may try
Me.tabAdjustment.object.value = 0

 
That was the trick. You are a genius, thank you!

Is this where Access and VB diverge? I have never known such a thing in VB.

Thanks again, I don't think I would ever have got to that solution.

Danny

[rockband] [wiggle][wiggle][wiggle]
 
Not really a genius, I only know how to make it work but I need someone to explain how and why to me. But this explained a little to me. I was testing the code in Excel and had no problem. The reason why (I think) was that Excel uses MSForms so there was no container object used on the MSForm tab strip. Therefore I could access the properties directly. When you use an MSForms control in access Forms it "places" the control in a container.
from help menu

OLE container control

A Visual Basic control that is used to link and embed objects from other applications in a Visual Basic application.
[/code]
Therefore you need to access the object within the container. This is a guess. Like I said, I need someone smarter to explain it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top