Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
KaW KaW is offline
external usenet poster
 
Posts: 1
Default Custom Form Coding


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

--
Ka
-----------------------------------------------------------------------
KaW's Profile: http://www.msusenet.com/member.php?userid=80
View this thread: http://www.msusenet.com/t-187013566

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Custom Form Coding

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.

--

Vasant


"KaW" wrote in message
...

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

It pops up when the program is run, and it contains 5 radio button
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 become
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 project
and the teacher failed to teach us anything about forms!

~Katie


--
KaW
------------------------------------------------------------------------
KaW's Profile: http://www.msusenet.com/member.php?userid=808
View this thread: http://www.msusenet.com/t-1870135661



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Custom Form Coding

Sorry:

strName = ctl.Name

should be:

strName = ctl.Caption

--

Vasant


"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
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.

--

Vasant


"KaW" wrote in message
...

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

It pops up when the program is run, and it contains 5 radio button
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 become
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 project
and the teacher failed to teach us anything about forms!

~Katie


--
KaW
------------------------------------------------------------------------
KaW's Profile: http://www.msusenet.com/member.php?userid=808
View this thread: http://www.msusenet.com/t-1870135661





  #4   Report Post  
Posted to microsoft.public.excel.programming
KaW KaW is offline
external usenet poster
 
Posts: 1
Default Custom Form Coding


Yes I meant the caption.

Should all of my code be in that If where it says "'run your code wit
strName"? That's got me confused, but the OK button is now workin
fine.

I'm just not sure how to get the value of strName into the rest of th
Module code I have

--
Ka
-----------------------------------------------------------------------
KaW's Profile: http://www.msusenet.com/member.php?userid=80
View this thread: http://www.msusenet.com/t-187013566

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Custom Form Coding

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

--

Vasant

"KaW" wrote in message
...

Yes I meant the caption.

Should all of my code be in that If where it says "'run your code with
strName"? That's got me confused, but the OK button is now working
fine.

I'm just not sure how to get the value of strName into the rest of the
Module code I have.


--
KaW
------------------------------------------------------------------------
KaW's Profile: http://www.msusenet.com/member.php?userid=808
View this thread: http://www.msusenet.com/t-1870135661



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding Custom Date Functions in Excel [email protected] Excel Worksheet Functions 1 May 8th 09 10:01 AM
color coding custom number formats bob sacco Excel Discussion (Misc queries) 1 October 3rd 05 01:01 PM
color coding custom number formats bob sacco Excel Discussion (Misc queries) 2 October 3rd 05 11:58 AM
User Form Coding bern Excel Discussion (Misc queries) 0 September 6th 05 04:51 PM
Efficient User Form vba coding for saving to worksheet Cheryl Excel Programming 1 July 23rd 04 02:07 PM


All times are GMT +1. The time now is 06:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"