+ Reply to Thread
Results 1 to 4 of 4

Creating a form with option buttons

  1. #1
    Jon
    Guest

    Creating a form with option buttons

    I need to create a user form that has 4 option buttons and an ok button
    to close the form. i have gotten the ok button to work fine with

    Private Sub OK_Click()
    Unload UserForm1
    End Sub

    but now i want to make the 4 option buttons set a variable to either
    1,2,3, or 4. How can I do this? Do i need code in the private sub for
    the button or in my main code? Thanks!


  2. #2
    Norman Jones
    Guest

    Re: Creating a form with option buttons

    Hi Jon,

    In a standard module, before any code, paste:

    Public myVar As Long

    Then, in the userform module, try:

    '=============>>
    Private Sub OptionButton1_Click()
    myVar = 1
    End Sub

    Private Sub OptionButton2_Click()
    myVar = 2
    End Sub

    Private Sub OptionButton3_Click()
    myVar = 3
    End Sub

    Private Sub OptionButton4_Click()
    myVar = 4
    End Sub
    '<<=============

    If you wish to reset the myVar variable each time that the form is opened,
    try:

    '=============>>
    Private Sub UserForm_Initialize()
    myVar = 0
    End Sub
    '<<=============

    This should be pasted in the userform module.


    ---
    Regards,
    Norman


    "Jon" <[email protected]> wrote in message
    news:[email protected]...
    >I need to create a user form that has 4 option buttons and an ok button
    > to close the form. i have gotten the ok button to work fine with
    >
    > Private Sub OK_Click()
    > Unload UserForm1
    > End Sub
    >
    > but now i want to make the 4 option buttons set a variable to either
    > 1,2,3, or 4. How can I do this? Do i need code in the private sub for
    > the button or in my main code? Thanks!
    >




  3. #3
    Tom Ogilvy
    Guest

    Re: Creating a form with option buttons

    Without knowing more, possibly:

    Public v as Integer
    Private Sub OptionButton1_Click()
    v = 1
    End Sub

    Private Sub OptionButton2_Click()
    v = 2
    End Sub

    Private Sub OptionButton3_Click()
    v = 3
    End Sub

    Private Sub OptionButton4_Click()
    v = 4
    End Sub

    --
    Regards,
    Tom Ogilvy


    "Jon" <[email protected]> wrote in message
    news:[email protected]...
    > I need to create a user form that has 4 option buttons and an ok button
    > to close the form. i have gotten the ok button to work fine with
    >
    > Private Sub OK_Click()
    > Unload UserForm1
    > End Sub
    >
    > but now i want to make the 4 option buttons set a variable to either
    > 1,2,3, or 4. How can I do this? Do i need code in the private sub for
    > the button or in my main code? Thanks!
    >




  4. #4
    Jon
    Guest

    Re: Creating a form with option buttons

    Thanks. My error was that I did not define the variable as public.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1