Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Option Buttons Added at Run Time

I have a form that adds and systematically names an unknown number of
option groups at run-time.

I simply don't know the syntax for retrieving info about these buttons
after they've been created.

Say I've created a two option groups (1 and 2) with three buttons each
(A1, B1, C1, A2, C2, B2).
If I was creating a button ahead of time, I could use:

debug.print OptionButton1.Value

so why does
debug.print A1.Value
or
debug.print OptionButtons("A1").value
give an error message and how should I be calling it?

Eventually I'd like to loop through each option group on the form, but
I'll be off and running with just a little hint about how to reference
these option buttons. Thank you so so much!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Option Buttons Added at Run Time

The form compiles when it loads so you won't be able to refer to
subsequently added objects simply by object-name. But you can use
me.controls(string-Name)...., or

Private Sub UserForm_Click()
Dim ob As MSForms.OptionButton
Dim s As String
On Error Resume Next

Set ob = Me.Controls("A1")

If ob Is Nothing Then
Set ob = Me.Controls.Add("Forms.OptionButton.1", "A1", True)
ob.Caption = "Option A1"
s = ob.Name & " created"
Else
s = ob.Name & " already existed"
End If

MsgBox s & vbCr & ob.Value
End Sub

If you need to trap events of the newly added controls you will need a
'WithEvents' class module.

Regards,
Peter T


wrote in message
ups.com...
I have a form that adds and systematically names an unknown number of
option groups at run-time.

I simply don't know the syntax for retrieving info about these buttons
after they've been created.

Say I've created a two option groups (1 and 2) with three buttons each
(A1, B1, C1, A2, C2, B2).
If I was creating a button ahead of time, I could use:

debug.print OptionButton1.Value

so why does
debug.print A1.Value
or
debug.print OptionButtons("A1").value
give an error message and how should I be calling it?

Eventually I'd like to loop through each option group on the form, but
I'll be off and running with just a little hint about how to reference
these option buttons. Thank you so so much!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
My CheckBoxes and Option Buttons Grow/Shrink each time I click the Memphis Excel Discussion (Misc queries) 1 April 15th 09 08:51 PM
remove multiple option buttons at one time Shuggles Excel Discussion (Misc queries) 3 May 22nd 07 08:09 PM
Option buttons: How to get the selected option from a group? naddad Excel Programming 5 December 21st 05 05:09 PM
Navigating between option buttons is not selecting the option drhalter Excel Programming 1 June 3rd 05 02:28 PM
Navigating between option buttons is not selecting the option Gixxer_J_97[_2_] Excel Programming 4 June 2nd 05 02:50 PM


All times are GMT +1. The time now is 11:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"