Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Forms & Check boxes 1

Status
Not open for further replies.

Murali27

Structural
Sep 28, 2002
147
Hi all

Please suggest me in the following situation;

I need to make a form with check boxes on it. The number of check boxes on the form should vary according to the values in the range of cells. say 3 horizontal& 3 vertically down.
(Like a matrix on the form)

so can i add the number of checkboxes to the form and assign the properties to them?

your input will be always appreciated
 
Replies continue below

Recommended for you

Murali27,

Here is a sample procedure that adds 3 checkboxes to a Userform. You will need to set the position properties for each created control, otherwise, they will be placed one on top of the other. Set additional properties as desired. You would call this from the Userform's Initialize event.

Code:
Sub AddCheckboxes()
Dim Ctrl As Control
Dim i As Integer

  For i = 1 To 3
    Set Ctrl = UserForm1.Controls.Add("Forms.Checkbox.1", "chk" & i, True)
    With Ctrl
    ' Set checkbox properties here
    End With
  Next i
  
End Sub


HTH
Mike
 
One thing

Say I am having 100 checkboxes on the form ( which depends on the input). I name the check boxes as chk 1, chk 2, ....

At one point of time i need to check the value of checkbox true or false. i just tried with For loop checking all checkboxes? I don't know the format by which the all check boxes can be checked using For loop at once.

please help me in this regard
 
Murali27,

The following procedure demonstrates a way to set the Value property of all your checkboxes. It takes one argument, ChkValue, which should be either 0 (unchecked) or 1 (checked). Note, this is at odds with the VBA Help, which indicates -1 for checked. I have found using -1 results in a checkmark with a gray background.

Code:
Sub SetCheckBoxes(ByVal ChkValue As Integer)
Dim Ctl As Control

  For Each Ctl In UserForm1.Controls
    If TypeName(Ctl) = "CheckBox" Then
      Ctl.Value = ChkValue
    End If
  Next Ctl

End Sub

The use of the TypeName function restricts the code to taking action on checkboxes only, excluding other Userform controls (buttons, listboxes, textboxes, etc.).


Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor