×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Forms & Check boxes

Forms & Check boxes

Forms & Check boxes

(OP)
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

RE: Forms & Check boxes

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.

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

RE: Forms & Check boxes

(OP)
Thanx alot msmith. It worked.

RE: Forms & Check boxes

(OP)
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

RE: Forms & Check boxes

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.

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

RE: Forms & Check boxes

(OP)
Thanks  msmith

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources