Form Initialized

C

ceemo

I have created a range of option buttons on my user form and have
grouped them in thecode as advised in the help files on VB. This works
fine however when i click between the option buttons the activie one
deactivates and i then have to click again to get the new selection to
hghlight.

Id rather it switched with one click rather than two, can this be
done?and what am i doing wrong?


Here's my code i run when the form is initalised

OptionButton5.GroupName = "Weeks"
OptionButton6.GroupName = "Weeks"
OptionButton7.GroupName = "Weeks"
OptionButton8.GroupName = "Weeks"
OptionButton9.GroupName = "Weeks"
 
D

Doug Glancy

ceemo,

That works for me - one click selects the new button (XL 03). Maybe you
should show us more code.

Doug
 
C

ceemo

Hi here's the full code

Private Sub UserForm_Initialize()

Sheets("info").Activate

Let myweek = Range("K25")
Let Range("AE2") = False
Let Range("AF2") = False
Let Range("AG2") = False
Let Range("AH2") = False
Let Range("AI2") = False
Let Range("AJ2") = False
Let Range("AK2") = False
Let Range("AL2") = False
Let Range("I27") = True


ComboBox1.ListRows = Range("AB53")

If myweek = 1 Then GoTo week1:
If myweek = 2 Then GoTo week2:
If myweek = 3 Then GoTo week3:
If myweek = 4 Then GoTo week4:
GoTo join:



week1:
OptionButton6.Enabled = False
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
GoTo join:

week2:
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
GoTo join:


week3:
OptionButton8.Enabled = False
OptionButton9.Enabled = False
GoTo join:

week4:
OptionButton9.Enabled = False
GoTo join:


join:
'Weekcommencing
OptionButton5.GroupName = "Weeks"
OptionButton6.GroupName = "Weeks"
OptionButton7.GroupName = "Weeks"
OptionButton8.GroupName = "Weeks"
OptionButton9.GroupName = "Weeks"
'OptionButton6.Value = False


'Combo box1
Let mycombo1 = Range("AB54").Value
ComboBox1.RowSource = mycombo1

'Combo box 2
mycombo2 = Range("U19")
ComboBox2.ColumnCount = 5
ComboBox2.RowSource = mycombo2
ComboBox2.ControlSource = "R2"
ComboBox2.BoundColumn = 1

'Telephony Skills
OptionButton1.GroupName = "Widgets"
OptionButton2.GroupName = "Widgets"
OptionButton3.GroupName = "Widgets"
OptionButton4.GroupName = "Widgets"


End Sub
 
D

Doug Glancy

ceemo,

Do you know for a fact that Join is executed? Have you stepped the code
with the debugger?

Gotos are generally discouraged as they can make it hard to trace the
execution of your code. Here's an alternative module. I commented out the
myCombo/ComboBox section as I didn't understand it, but the option buttons
behave as they should:

Private Sub UserForm_Initialize()

Dim myweek As Long

With Sheets("info")
myweek = .Range("K25")
.Range("AE2:al2") = False
.Range("I27") = True
End With

ComboBox1.ListRows = Range("AB53")

If myweek = 1 Then
OptionButton6.Enabled = False
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
ElseIf myweek = 2 Then
OptionButton7.Enabled = False
OptionButton8.Enabled = False
OptionButton9.Enabled = False
ElseIf myweek = 3 Then
OptionButton8.Enabled = False
OptionButton9.Enabled = False
ElseIf myweek = 4 Then
OptionButton9.Enabled = False
End If

'Weekcommencing
OptionButton5.GroupName = "Weeks"
OptionButton6.GroupName = "Weeks"
OptionButton7.GroupName = "Weeks"
OptionButton8.GroupName = "Weeks"
OptionButton9.GroupName = "Weeks"
'OptionButton6.Value = False

''Combo box1
'mycombo1 = Range("AB54").Value
'ComboBox1.RowSource = mycombo1
'
''Combo box 2
'mycombo2 = Range("U19")
'ComboBox2.ColumnCount = 5
'ComboBox2.RowSource = mycombo2
'ComboBox2.ControlSource = "R2"
'ComboBox2.BoundColumn = 1

'Telephony Skills
OptionButton1.GroupName = "Widgets"
OptionButton2.GroupName = "Widgets"
OptionButton3.GroupName = "Widgets"
OptionButton4.GroupName = "Widgets"
End Sub
 
C

ceemo

Well i deleted the buttons and set them back up as they were and no
they work so they must have become corrupt. Thanks for coding tips
 

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