Option Buttons Settings

Option Buttons Settings

Anonymous
Not applicable
467 Views
7 Replies
Message 1 of 8

Option Buttons Settings

Anonymous
Not applicable
I have the following code in my userform_activate which sets the correct option button
based upon the value of chkAutoCapFlag:

' This section only here because I don't know what's causing the problem...
chkNoCaseChange.Value = False
chkAutoCap.Value = False
chkUPRCASE.Value = False
'End section

Select Case chkAutoCapFlag
Case 0
chkNoCaseChange.Value = True
Case 1
chkAutoCap.Value = True
Case 2
chkUPRCASE.Value = True
End Select

If the chkAutoCapFlag = 2, when the form loads the chkUPRCASE button is checked, but the
chkAutoCap button is checked but disabled.
It appears correct when chkAutoCapFlag is either 0 or 1 though.
All these controls are set to FALSE in the design view. Setting them all to false before
setting the appropriate one to true in code doesn''t seem to work either.



Any ideas?
0 Likes
468 Views
7 Replies
Replies (7)
Message 2 of 8

GTVic
Advisor
Advisor
What is chkAutoCapFlag (variable or control)? Where is it set?

If chkAutoCapFlag is not a CheckBox then you should change the name to something like flagAutoCap.

The other controls are option buttons so only one should be highlighted at a time. I don't see how you can get two of them on at once. Also, to avoid confusion, the names should start with opt instead of chk.
0 Likes
Message 3 of 8

Anonymous
Not applicable
wrote in message news:4983924@discussion.autodesk.com...
What is chkAutoCapFlag (variable or control)? Where is it set?

It's a variable, set previous to the code fragment in question. For the condition
indicated to occur, chkAutoCapFlag = 2.

If chkAutoCapFlag is not a CheckBox then you should change the name to something like
flagAutoCap.

That's not relavent to the question.

The other controls are option buttons so only one should be highlighted at a time. I don't
see how you can get two of them on at once.

They are option buttons. And what you see is what I see. I realize that you can't have
two checked at the same time! But obviously, it is happening here. That is the point of
the question!

Also, to avoid confusion, the names should start with opt instead of chk.

Granted, but that's not relevant to the question.
0 Likes
Message 4 of 8

Anonymous
Not applicable
Ok, the problem was that later on in the userform_activate event, chkAutoCap got set to
True. Since VBA knows you can't have two True values, it grayed it out. Why it didn't
change the value for chkUPRCASE to false when that occurred, I don't know.
0 Likes
Message 5 of 8

Anonymous
Not applicable
Sample code to demonstrate what was happening:

Private Sub UserForm_Initialize()
Dim flgAutoCaps As Integer
flgAutoCaps = 2
Select Case flgAutoCaps
Case 0
optNoCaseChange.Value = True
Case 1
optAutoCap.Value = True
Case 2
optUPRCASE.Value = True
End Select

optAutoCap.Value = flgAutoCaps ' grays out the option button, while also setting its
value to true.

End Sub
0 Likes
Message 6 of 8

GTVic
Advisor
Advisor
If you set optAutoCap to flgAutoCaps (which is 2) then apparently that is the same as setting it to Null. Null means it contains no valid data according to the online help.

So what you are getting is designed behaviour. The reason why is that you are using a value other than True or False.
0 Likes
Message 7 of 8

GTVic
Advisor
Advisor
See here:
http://www.fontstuff.com/casebook/casebook05.htm
0 Likes
Message 8 of 8

Anonymous
Not applicable
You'd think that "designed behavior" would be to raise an error, since you are sending an
"illegal" value, i.e. not True, False, or Null.


wrote in message news:4984088@discussion.autodesk.com...
If you set optAutoCap to flgAutoCaps (which is 2) then apparently that is the same as
setting it to Null. Null means it contains no valid data according to the online help.

So what you are getting is designed behaviour. The reason why is that you are using a
value other than True or False.
0 Likes