Rufus Clupea
Board Regular
- Joined
- Feb 11, 2019
- Messages
- 85
Hi Folks,
I'm trying to get a process involving OptionButtons to work, but the logic is eluding me (been struggling with it on & off for several days). I'm hoping someone here can help/nudge me in the right direction...
On a UserForm, I have a Frame containing several (10) OptionButtons. The intention is that if/when a user selects an OptionButton different than the default choice (#5)—or subsequently changes their choice—they're prompted with a MsgBox informing them, "Changing OptionButton selection may change some Variables. Do you wish to Continue?" (Y/N)
As it stands, the code works for a "Yes" (Continue) response, but I can't seem to get it to revert to the previous choice if the user clicks "No".
Here's the (sample) code. The problem is in/with Sub Choose_OB(row As Long)
THX!
I'm trying to get a process involving OptionButtons to work, but the logic is eluding me (been struggling with it on & off for several days). I'm hoping someone here can help/nudge me in the right direction...
On a UserForm, I have a Frame containing several (10) OptionButtons. The intention is that if/when a user selects an OptionButton different than the default choice (#5)—or subsequently changes their choice—they're prompted with a MsgBox informing them, "Changing OptionButton selection may change some Variables. Do you wish to Continue?" (Y/N)
As it stands, the code works for a "Yes" (Continue) response, but I can't seem to get it to revert to the previous choice if the user clicks "No".
Here's the (sample) code. The problem is in/with Sub Choose_OB(row As Long)
Code:
[FONT=courier new][COLOR=#0000ff]Option Explicit[/COLOR]
[COLOR=#0000ff]Public [/COLOR]Previous_OB [COLOR=#0000ff]As Long[/COLOR]
[COLOR=#0000ff]Public [/COLOR]Current_OB [COLOR=#0000ff]As Long[/COLOR]
[COLOR=#0000ff]Sub [/COLOR]UserForm_Initialize()
Current_OB = 5
Previous_OB = Current_OB
UserForm1.OptionButton5.Value = [COLOR=#0000ff]True[/COLOR]
Highlight_OB 5, 5
[COLOR=#0000ff]End Sub[/COLOR] [COLOR=#008000]'UserForm_Initialize()[/COLOR]
[COLOR=#0000ff]Sub [/COLOR]Choose_OB(row [COLOR=#0000ff]As Long[/COLOR])
[COLOR=#0000ff]Dim [/COLOR]i [COLOR=#0000ff]As Long[/COLOR]
Current_OB = row
[COLOR=#0000ff]If[/COLOR] MsgBox("Changing OptionButton selection may change some" & Chr(13) & _
"Variables." & Chr(13) & Chr(13) & _
"Do you wish to continue?", 68, "Changing Choice") = vbNo [COLOR=#0000ff]Then[/COLOR]
UserForm1.Controls("OptionButton" & Previous_OB).Value = [COLOR=#0000ff]True[/COLOR]:
UserForm1.Controls("OptionButton" & Current_OB).SetFocus
[COLOR=#0000ff] End If[/COLOR]
Current_OB = Previous_OB
Highlight_OB 1, 10
[COLOR=#0000ff]End Sub[/COLOR][COLOR=#008000] 'Choose_OB(row As Long)[/COLOR]
[COLOR=#0000ff]Sub [/COLOR]Highlight_OB(Low [COLOR=#0000ff]As Long[/COLOR], High [COLOR=#0000ff]As Long[/COLOR])
[COLOR=#0000ff]Dim[/COLOR] i [COLOR=#0000ff]As Long[/COLOR]
[COLOR=#0000ff]For[/COLOR] i = Low [COLOR=#0000ff]To[/COLOR] High
[COLOR=#0000ff]With[/COLOR] UserForm1.Controls("OptionButton" & i)
[COLOR=#0000ff]If[/COLOR] .Value = [COLOR=#0000ff]True Then[/COLOR] [COLOR=#008000]'Embolden Choice[/COLOR]
.Font.Bold = [COLOR=#0000ff]True[/COLOR]:
.ForeColor = &H80000012:
.TabStop = [COLOR=#0000ff]True[/COLOR]
[COLOR=#0000ff]Else[/COLOR] [COLOR=#008000]'Gray Out Everything Else[/COLOR]
.Font.Bold = [COLOR=#0000ff]False[/COLOR]:
.ForeColor = &H80000011:
.TabStop = [COLOR=#0000ff]False[/COLOR]
[COLOR=#0000ff]End If[/COLOR]
[COLOR=#0000ff]End With[/COLOR]
[COLOR=#0000ff]Next [/COLOR]i
[COLOR=#0000ff]End Sub[/COLOR] [COLOR=#008000]'Highlight_OB(Low As Long, High As Long)[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton1_Click()
Choose_OB 1
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton2_Click()
Choose_OB 2
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton3_Click()
Choose_OB 3
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton4_Click()
Choose_OB 4
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton5_Click()
Choose_OB 5
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton6_Click()
Choose_OB 6
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton7_Click()
Choose_OB 7
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton8_Click()
Choose_OB 8
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton9_Click()
Choose_OB 9
[COLOR=#0000ff]End Sub[/COLOR]
[COLOR=#0000ff]Private Sub[/COLOR] OptionButton10_Click()
Choose_OB 10
[COLOR=#0000ff]End Sub[/COLOR][/FONT]
THX!