creating string reference to control

B

Basil

Hiya,

I have a load of tabs page1, page2, page3, etc

I have an option group above. When the user clicks the option, it will
return a value (1,2,3,4,...). I want it to set focus to the corresponding
page but am having trouble making a dynamic reference to the page control.
Can you help please?

This is my code that is failing:

Private Sub frameUpdate_Click()

Dim pg As String 'also doesn't work when set to be a Control

pg = "Page" & frameUpdate.Value
Me.[pg].SetFocus

End Sub

Thanks loads,

Basil
 
R

RoyVidar

Basil said:
Hiya,

I have a load of tabs page1, page2, page3, etc

I have an option group above. When the user clicks the option, it
will return a value (1,2,3,4,...). I want it to set focus to the
corresponding page but am having trouble making a dynamic reference
to the page control. Can you help please?

This is my code that is failing:

Private Sub frameUpdate_Click()

Dim pg As String 'also doesn't work when set to be a Control

pg = "Page" & frameUpdate.Value
Me.[pg].SetFocus

End Sub

Thanks loads,

Basil

I think you would need to refer through the tab

pg = "Page" & frameUpdate.Value
Me!MyTab.Pages(pg).SetFocus
 
B

Basil

Thanks Roy.

I'm pretty sure there's another way though that is more simple and widely
useable. I asked the question before but MSDN removed it. (the work is at a
previous company so can't reference).

Thanks though, I'll use this in the meantime.

B

RoyVidar said:
Basil said:
Hiya,

I have a load of tabs page1, page2, page3, etc

I have an option group above. When the user clicks the option, it
will return a value (1,2,3,4,...). I want it to set focus to the
corresponding page but am having trouble making a dynamic reference
to the page control. Can you help please?

This is my code that is failing:

Private Sub frameUpdate_Click()

Dim pg As String 'also doesn't work when set to be a Control

pg = "Page" & frameUpdate.Value
Me.[pg].SetFocus

End Sub

Thanks loads,

Basil

I think you would need to refer through the tab

pg = "Page" & frameUpdate.Value
Me!MyTab.Pages(pg).SetFocus
 
S

Scott McDaniel

Basil said:
Hiya,

I have a load of tabs page1, page2, page3, etc

I have an option group above. When the user clicks the option, it
will return a value (1,2,3,4,...). I want it to set focus to the
corresponding page but am having trouble making a dynamic reference
to the page control. Can you help please?

This is my code that is failing:

Private Sub frameUpdate_Click()

Dim pg As String 'also doesn't work when set to be a Control

pg = "Page" & frameUpdate.Value
Me.[pg].SetFocus

End Sub

Thanks loads,

Basil

I think you would need to refer through the tab

pg = "Page" & frameUpdate.Value
Me!MyTab.Pages(pg).SetFocus

I've had some odd instances where the above didn't work correctly (for the most part, it works perfectly fine), however
I've always used the Cstr function to make sure:

pg = "Page" & Cstr(frameUpdate.Value)



Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
B

Baz

The value of a tab control is the ordinal position of the current page, so
this will display the page corresponding to your option buttons:

tabOfMine.Value = frameUpdate.Value


Basil said:
Thanks Roy.

I'm pretty sure there's another way though that is more simple and widely
useable. I asked the question before but MSDN removed it. (the work is at a
previous company so can't reference).

Thanks though, I'll use this in the meantime.

B

RoyVidar said:
Basil said:
Hiya,

I have a load of tabs page1, page2, page3, etc

I have an option group above. When the user clicks the option, it
will return a value (1,2,3,4,...). I want it to set focus to the
corresponding page but am having trouble making a dynamic reference
to the page control. Can you help please?

This is my code that is failing:

Private Sub frameUpdate_Click()

Dim pg As String 'also doesn't work when set to be a Control

pg = "Page" & frameUpdate.Value
Me.[pg].SetFocus

End Sub

Thanks loads,

Basil

I think you would need to refer through the tab

pg = "Page" & frameUpdate.Value
Me!MyTab.Pages(pg).SetFocus
 
R

RoyVidar

Baz said:
The value of a tab control is the ordinal position of the current
page, so this will display the page corresponding to your option
buttons:

tabOfMine.Value = frameUpdate.Value


Basil said:
Thanks Roy.

I'm pretty sure there's another way though that is more simple and
widely useable. I asked the question before but MSDN removed it.
(the work is at a previous company so can't reference).

Thanks though, I'll use this in the meantime.

B

RoyVidar said:
<[email protected]>:
Hiya,

I have a load of tabs page1, page2, page3, etc

I have an option group above. When the user clicks the option, it
will return a value (1,2,3,4,...). I want it to set focus to the
corresponding page but am having trouble making a dynamic
reference to the page control. Can you help please?

This is my code that is failing:

Private Sub frameUpdate_Click()

Dim pg As String 'also doesn't work when set to be a Control

pg = "Page" & frameUpdate.Value
Me.[pg].SetFocus

End Sub

Thanks loads,

Basil

I think you would need to refer through the tab

pg = "Page" & frameUpdate.Value
Me!MyTab.Pages(pg).SetFocus

Isn't it zero based?

Me!MyTab.Value = frameUpdate.Value - 1

(or renumber the options starting with 0?)
 

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