Disabling/enabling option buttons

G

Guest

==You all helped me tremendously last week... please do it again!===

I have as many as nine groups of items from which to select one of up to
nine items. The groups are coded by tens (e.g., 10, 20, 30, etc.) and the
items are in the decade of their group (e.g., Item 11 belongs to Group 10).
A group may not have nine items, and, for matricing purposes, are not densely
numbered (e.g., Items 14 and 18 are missing from Group 10).

I have a dialog form whose sole control (an option group) is dynamically
populated based on the group identified by the calling form. The form only
allows form view, additions, and data entry; it is a pop-up, is modal, and
has the dialog border style. The option group is visible, enabled, and not
locked. The option buttons are named opt1, opt2, etc., and the corresponding
labels are named lblOption1, lblOption2, etc.

I want to disable option buttons that do not have corresponding items. The
option button labels are successfully populated by the attached Form_Open
event procedure, but the buttons themselves cannot be selected. What am I
doing wrong?

With Me
.Caption = strGroupType & " Type"
.lbl_grpDetailType.Caption = strGroupType
For i = 1 To 9
strDetailType = CStr(OpenArgs * 10 + i)
str_opt = "opt" & CStr(i)
str_lbl = "lblOption" & CStr(i)
rstDetailType.Seek "=", strDetailType
If rstDetailType.NoMatch Then
.Controls(str_opt).Enabled = False
.Controls(str_lbl).Visible = False
Else
.Controls(str_opt).Enabled = True
With .Controls(str_lbl)
.Visible = True
.Caption = fldDetailType
End With
End If
Next
End With

I'm also a kick-it-'til-it-works developer, so if an easier or more
efficient approach exists, please share it!

You all are the best!
 
R

Rob Oldfield

Nothing leaps out at me as being wrong. The best thing to do to start off
with in this kind of situation is to add a breakpoint into your code and
then step through it line by line to see if the code is going the wrong way
at some point. To do that...

Right click on the line that you want to put a breakpoint on - in this case
I'd guess maybe the strDetailType = CStr(OpenArgs * 10 + i)
one - then Toggle, Breakpoint. The line will be highlighted in a nice brown
colour.

Kick your code off as usual by opening the form. The code will stop at the
breakpoint which will now be yellow.

Hit F8 and it will move to the next line to be processed. Keep doing that
to step through your code.

If you hit F5 then code will continue normally (until it hits another
breakpoint - you can set as many as you want.)

While that's happening you can wave the mouse at variables and you'll get a
little display to tell you, for example, what the variable str_opt is set to
just at the moment.

Does that give you any clues to what's going wrong?
 

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