Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gain control of userforms/control boxes

Status
Not open for further replies.

jluft

Technical User
May 4, 2004
74
US
trying to assign names of various boxes to an array

ie testarray = Array("Check1","Check2","Check3")

then based on value of a different control box change the values of these in the array to conform

ie

if checkall.value = true then
for i = 1 to 3
testarray(i).value = true
next i
else
for i = 1 to 3
testarray(i).value = false
next i
end if

this is not working..."Object doesnt support this method or property" is the error msg that i receive...does anyone have any idea as to how i can correct this problem? thanks
 
Here is an example that may help. A UserForm with four checkboxes:

1. in code module - NOT form module - put Public array
Public cNames(3) As String. cNames will hold the control names.

2. In Intialize event of the form:
cNames(0) = "CheckBox1"
cNames(1) = "CheckBox2"
cNames(2) = "CheckBox3"
cNames(3) = "CheckBox4"

3. Then something like:
Code:
Sub CheckBox1_Click()
Dim ctrl As Control
Dim var
Dim i As Integer
On Error Resume Next
Set ctrl = UserForm1.Controls(cNames(0))
If ctrl.Object.Value = True Then
    For var = 1 To 4
        Set ctrl = Nothing
        Set ctrl = UserForm1.Controls(cNames(i))
        ctrl.Object.Value = True
        i = i + 1
    Next
Else
        For var = 1 To 4
        Set ctrl = Nothing
        Set ctrl = UserForm1.Controls(cNames(i))
        ctrl.Object.Value = False
        i = i + 1
    Next
End If
Set ctrl = Nothing
End Sub
This takes the value of Checkbox1 and resets all the other checkboxes to match.

This is actually fairly sloppy, but it may give you some ideas for where you can go.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top