+ Reply to Thread
Results 1 to 4 of 4

Select option button when have the name as a string

  1. #1
    Debbie Probert via OfficeKB.com
    Guest

    Select option button when have the name as a string

    Hi All

    During the running of my VBA code, I collect the name of an option button from an Access database. I then want to set the value of the option button on a form. My problem is that I have the name of the button as a string and just cannot see how to use that to set the value of the button on the form as, when used as a string, I get an error.

    Hope the question makes sense to someone :-)

    Many thanks
    Deb

    --
    Message posted via http://www.officekb.com

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Quote Originally Posted by Debbie Probert via OfficeKB.com
    Hi All

    During the running of my VBA code, I collect the name of an option button from an Access database. I then want to set the value of the option button on a form. My problem is that I have the name of the button as a string and just cannot see how to use that to set the value of the button on the form as, when used as a string, I get an error.

    Hope the question makes sense to someone :-)

    Many thanks
    Deb

    --
    Message posted via http://www.officekb.com

    Hello Deb,

    What you want to do is a very useful programming approach. VBA does it. However, the literature never reallys makes it quite clear how to it. So, here is how...
    ________________________________________________________________

    Dim OptBtn As Object
    Dim OptBtn_Name As String

    'Set UserForm1 to the Name of the Form the Control is on
    Set OptBtn = UserForm1.Controls(OptBtn_Name)

    OptBtn.Value = True 'To set it
    OptBtn.Value = False 'To Clear it
    ________________________________________________________________

    Hope Tthis helps,
    Leith Ross

  3. #3
    Bob Phillips
    Guest

    Re: Select option button when have the name as a string

    Deb,

    Use
    Me.Controls(string_value)

    with whatever property you want

    --
    HTH

    Bob Phillips

    "Debbie Probert via OfficeKB.com" <forum@OfficeKB.com> wrote in message
    news:f4b38b89f72846d0aabc3123187a052b@OfficeKB.com...
    > Hi All
    >
    > During the running of my VBA code, I collect the name of an option button

    from an Access database. I then want to set the value of the option button
    on a form. My problem is that I have the name of the button as a string and
    just cannot see how to use that to set the value of the button on the form
    as, when used as a string, I get an error.
    >
    > Hope the question makes sense to someone :-)
    >
    > Many thanks
    > Deb
    >
    > --
    > Message posted via http://www.officekb.com




  4. #4
    Tom Ogilvy
    Guest

    Re: Select option button when have the name as a string

    Private Sub CommandButton2_Click()
    sStr = "Button Name"
    UserForm1.Optionbutton1.Caption = sStr
    End Sub

    I assume by name you mean the name you would see next to the button on the
    form.

    --
    Regaards,
    Tom Ogilvy



    "Debbie Probert via OfficeKB.com" <forum@OfficeKB.com> wrote in message
    news:f4b38b89f72846d0aabc3123187a052b@OfficeKB.com...
    > Hi All
    >
    > During the running of my VBA code, I collect the name of an option button

    from an Access database. I then want to set the value of the option button
    on a form. My problem is that I have the name of the button as a string and
    just cannot see how to use that to set the value of the button on the form
    as, when used as a string, I get an error.
    >
    > Hope the question makes sense to someone :-)
    >
    > Many thanks
    > Deb
    >
    > --
    > Message posted via http://www.officekb.com




+ 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