vendredi 2 juin 2017

Write Text to Word Doc with Checkbox Control Form

I have a userform with checkboxes that writes text to a bookmarked location. The vba was done by a previous person and I'm having a bit of trouble adding additional text groupings. The form is set up with 8 checkboxes. I've added the additional checkbox to the form itself and I've inserted a new string with the text that needs to be added. It is strProtest below. I've attempted to mimic the other string's structure, but I'm receiving a run-time error '9': Subscript out of range.

The debugging identifies the "strOptions = strOptions & vOption(cbItem.TabIndex)" as the problematic line.

Thank you very much, in advance.

Dim vOption


Private Sub cmdOK_Click()

    Dim cbItem As Control
    Dim PrintOptions

    strOptions = ""  'initializes variable

'populates variable strOptions based on check boxes for use with 
 Module1.EnterText
    For Each cbItem In Me.Controls
        If TypeName(cbItem) = "CheckBox" Then
            If cbItem Then _
                strOptions = strOptions & vOption(cbItem.TabIndex)
        End If
    Next cbItem

    If strOptions = "" Then  'no options selected
        Unload Me
        Exit Sub
    End If

    Me.Hide

    Call EnterText

    MsgBox "The letter has been updated.", _
        vbInformation + vbOKOnly, "Customize Wording"

    Unload Me

End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()

'adds text to the various checkbox controls

    Dim strInsufficient_Doc_Request As String
    Dim strInsufficient_Doc_Deny As String
    Dim strDeny_Single_Issue As String
    Dim strUntimely_Deny As String
    Dim strNPR_Not_Issued As String
    Dim strImmaterial As String
    Dim strIssue_Already_Reviewed As String
    Dim strDNQ_DSH As String
    Dim strProtest As String

    strInsufficient_Doc_Request = "Text to Write"

    strInsufficient_Doc_Deny = "Text to Write"

    strDeny_Single_Issue = "Text to Write"

    strUntimely_Deny = "Text to Write"

    strNPR_Not_Issued = "Text to Write"

    strImmaterial = "Text to Write"

    strIssue_Already_Reviewed = "Text to Write"

    strDNQ_DSH = "Text to Write"

    strProtest = "Text to Write"

    vOption = Array( _
        strInsufficient_Doc_Request & vbCr & vbCr, _
        strInsufficient_Doc_Deny & vbCr & vbCr, _
        strDeny_Single_Issue & vbCr & vbCr, _
        strUntimely_Deny & vbCr & vbCr, _
        strNPR_Not_Issued & vbCr & vbCr, _
        strImmaterial & vbCr & vbCr, _
        strIssue_Already_Reviewed & vbCr & vbCr, _
        strDNQ_DSH & vbCr & vbCr, _
        strProtest & vbCr & vbCr)

End Sub




Aucun commentaire:

Enregistrer un commentaire