Custom Form Coding

K

KaW

I have created a custom form for my VBA program, however I'm not sure o
how it should be coded.

It pops up when the program is run, and it contains 5 radio butto
choices as well as an "OK" and "Cancel" button.

What I would like to happen is the user selects one of the 5 buttons
and then hits ok. The value from the radio button I'd like to becom
the variable 'name' and I'd like OK to run the rest of the program.

Any help would be greatly appreciated, as this is for a class projec
and the teacher failed to teach us anything about forms!

~Kati
 
V

Vasant Nanavati

What do you mean by the "value from the radio button?" Radio buttons have
only 2 values; True and False.

If you mean the **caption** of the radio button:

Sub CommandButton1_Click()
'assuming CommandButton1 is the OK button
Dim ctl As Control, strName As String
For Each ctl In Controls
If TypeOf ctl Is MsForms.OptionButton Then
If ctl Then
strName = ctl.Name
Exit For
End If
End If
Next
If strName <> vbNullString Then
'run your code with strName
End If
Unload Me
End Sub


Name is a reserved word and should not be used as a variable; use strName
instead.
 
V

Vasant Nanavati

Sorry:

strName = ctl.Name

should be:

strName = ctl.Caption

--

Vasant


Vasant Nanavati said:
What do you mean by the "value from the radio button?" Radio buttons have
only 2 values; True and False.

If you mean the **caption** of the radio button:

Sub CommandButton1_Click()
'assuming CommandButton1 is the OK button
Dim ctl As Control, strName As String
For Each ctl In Controls
If TypeOf ctl Is MsForms.OptionButton Then
If ctl Then
strName = ctl.Name
Exit For
End If
End If
Next
If strName <> vbNullString Then
'run your code with strName
End If
Unload Me
End Sub


Name is a reserved word and should not be used as a variable; use strName
instead.
 
V

Vasant Nanavati

Yes, all the code should go in there. Try it and post back if you have more
questions.
 

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