+ Reply to Thread
Results 1 to 4 of 4

How can I "set" a checkbox name like i Set a worksheet?

  1. #1
    Registered User
    Join Date
    04-29-2004
    Posts
    92

    How can I "set" a checkbox name like i Set a worksheet?

    I know how to do this with worksheets, ranges and textboxes... But I cant figure out how to do it with a checkbox. I'd like to do this so I can call 1 module from several places while only changing the checkbox's number.. an example might look like this, although I need checkbox not textbox.

    set txtbox = userform3.controls("textbox" & i)

    Shouldnt be to hard for someone who knows


    Thanks in advance Chris

  2. #2
    Registered User
    Join Date
    04-29-2004
    Posts
    92
    Would think it would look like this

    '-----checknum will be the checkbox's number.

    sub commandbuttonclick()

    dim checknum as integer
    dim blahblah as integer

    if blahblah = 1 then
    checknum = 1
    end if

    if blahblah = 2 then
    checknum =2
    end if

    call checkbox_num(checknum)
    end sub

    '--------

    sub checkbox_num(checknum)

    dim chckbox as object '---This is really what im looking for
    set chckbox = userform1.controls("checkbox", & checknum) '---and this
    chckbox.value = true
    end sub
    '--------
    what do i dim my chckbox as and how do i apply a variable to the checkboxes number such as the ("checkbox". & checknum)?


    Thanks again
    Chris
    Last edited by justchris; 05-23-2005 at 08:53 AM.

  3. #3
    Forum Contributor
    Join Date
    06-10-2004
    Location
    India
    Posts
    1,066
    Hi JustChris,

    I tried your code and it works real nice.

    This is what I tried:

    Private Sub CommandButton1_Click()

    Dim checknum As Integer
    Dim blahblah As Integer

    If TextBox1 = 1 Then
    checknum = 1
    End If

    If TextBox1 = 2 Then
    checknum = 2
    End If

    Call checkbox_num(checknum)
    End Sub

    Sub checkbox_num(checknum)

    Dim chckbox As Object

    Set chckbox = UserForm3.Controls("checkbox" & checknum)
    chckbox.Value = True

    End Sub


    Are you encountering any problems with this method

    - Mangesh

  4. #4
    Registered User
    Join Date
    04-29-2004
    Posts
    92
    Lol... right in front of me. I could have swore I tried that same line. Thats what I was looking for.


    I knew it was going to be easy , But not THAT easy

    Lol Thanks Mangesh

+ 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