Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Choosing from a userform (WinNT/Word97)

    Can anyone tell me a reasonably simple way to pick up which choice a user made from a selection of 12 checkboxes on a userform, where they can have chosen any combination of between 4 and 6 of the 12 available? I simply need to specify that var1 = the value assigned to the first box ticked, eg if box 3 is the first ticked, var1 = 3, and so on down the list ... then there are four levels for each choice, so I need to specify that if var1 = 3, var1L = the value for the optionbutton chosen, 1-4.

    I'm sorry to be asking such lame questions today but it's my first day back from holiday, this has been given me as ultra ultra urgent and I've forgotten to bring in my glasses so I'm rapidly getting a splitting headache.

    Any and all assistance appreciated.
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Choosing from a userform (WinNT/Word97)

    This is off the top of my head, so no guarantees.

    If you have named the check boxes with a number, something like chkChoice1 through chkChoice12, you can easily refer to them as Me.Controls("chkChoice" & i) where i is an integer variable. You can then loop through them, and keep track of how many checks you have encountered:

    Dim i As Integer
    Dim intChecks As Integer
    For i = 1 To 12
    If Me.Controls("chkChoice" & i).Value = True Then
    intChecks = intChecks + 1
    SetVar i, intChecks
    End If
    Next i

    SetVar is a procedure that sets a variable and looks at the corresponding option buttons. It would be easier if you had an array instead of Var1, Var2 etc., but I don't know if that is feasible. The assignment would just be arrVar(intChecks) = i. Otherwise:

    Sub SetVar(i As Integer, intChecks as Integer)
    Select Case intChecks
    Case 1
    Var1 = i
    Case 2
    Var2 = i
    ...
    Case 12
    Var12 = i
    End Select
    End Sub

    Looking at the option buttons could use a similar loop, but I don't have enough time to work that out now. I hope this will give you a start.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Choosing from a userform (WinNT/Word97)

    Thanks, Hans, I really do appreciate the help you provide!

    However, I'm not sure if this is quite what I was looking for - probably my fault for not explaining it better! I have 12 checkboxes, of which users can choose to use between 4 and 6. I therefore have only var1 through var6 to be populated, from the 12 choices, with the number of the choice; eg if user chooses 3rd, 5th, 6th, 8th and 10th options, then var1 = 3, var2 = 5, var3 = 6, var4 = 8, var5 = 10 and var6 would be blank.

    I don't entirely understand your code but I think it makes var1 = 1, var2 = 2 etc if the relevant checkbox is checked?
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Choosing from a userform (WinNT/Word97)

    Then how about something like

    Dim i As Integer
    Dim j As Integer
    Dim intVar(6) As Integer
    Dim intChecks As Integer
    For i = 1 To 12
    If Me.Controls("chkChoice" & i).Value = True Then
    if j > 6 then
    MsgBox "Too many"
    Exit Sub
    End If
    intVar(j) = i
    j = j + 1
    Next i

    (completely untested)

    StuartR

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Choosing from a userform (WinNT/Word97)

    Hello Beryl,

    My code would do what you want. I have attached a very simple demo doc (zipped) with just 4 check boxes. You must enter the VB Editor to run the form; output is to the immediate window.
    I still think that using an array arrVar(1 To 6) would be more convenient.

Posting Permissions

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