0

I've got several check boxes to which I am going to change the visibility and caption of based on the index of a for loop. I have an array of 1 to X. Into my form I am passing along the array total and each array element is a string.

Anyway, on my worksheet I am passing:

Sub Stripdown_Button_Click()
    LastUpdateColumn = Sheets("Update").UsedRange.Columns.Count
    Header_Array = Range(Cells(7, 1), Cells(7, LastUpdateColumn)).Value
    Header_Form.Header_Select LastUpdateColumn, Header_Array()
    Header_Form.Show
End Sub

LastUpdateColumn will be an integer, Header_Array will be an array of strings.

My form, which I am probably completely screwing up at this point is as follows...

Public Sub Header_Select(Index As Integer, Header_List() As String)

    For x = 1 To Index
        If Header_List(1) <> "" Then
            cb & Index.Visible = True
            cb & Index.Caption = Header_List(Index)
        Else
            MsgBox "Form Error. Contact Engineering", vbOKOnly
        On Error Resume Next
    End Sub
1
  • 1
    VB.NET and VBA are two completely different BASIC dialects. If you are working with MS Access, Word or Excel, you are probably using VBA. If you are working with Visual Studio, you are probably using VB.NET. Commented Jun 6, 2016 at 19:10

1 Answer 1

1

You cannot create a variable name from a string; however the forms have a Controls default property accepting a control name as index

Dim cb As CheckBox

Set cb =  Controls("cb" & Index)
cb.Visible = True
cb.Caption = Header_List(Index)

Since the property is the default property, this other syntax also works:

Set cb =  Me("cb" & Index)
Sign up to request clarification or add additional context in comments.

2 Comments

Genius, thanks so much. I just ran into another issue. It's not letting me pass "Range(Cells(7, 1), Cells(7, LastUpdateColumn)).Value" into my array variable. It's going into "Type mismatch". Everything is set as string. All the data is definetly simple text headers.
Set a breakpoint on the line with the problem and inspect the value. google.ch/search?q=how+to+debug+vba

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.