HTSCF Fareha
03-11-2021, 07:28 AM
Okay, I'm sure that there is a basic solution to this, but I've hit a complete brick wall that I cannot seem to knock down.
I have a scenario where a single TextBox might have two different types of input. These being "Yet to be determined.", which is the default and then any other entry. Both are targeted to the same Content Control.
The issue that I'm having is that the "Yet to be determined." needs to be formatted as per sentence, although the other option needs to be propercase with the last word uppercase (as per previous post 'Trying to apply two types of word case formatting to TextBox').
The nearest I get is the below, which shows the default as required, but "ignores" the second formatting case altogether.
Sub FillForm()
Dim oCtrl As Control
Dim oCC As ContentControl
Dim lngIndex As Long
Dim strTC As String
Dim oRng As Range
With m_oFrm
For Each oCtrl In .Controls
Select Case TypeName(oCtrl)
Case "TextBox"
If oCtrl.Name = "txtDescription" Then
Set oCC = ActiveDocument.SelectContentControlsByTag("Description").Item(1)
oCC.Range.Text = StrConv(oCtrl.Text, vbProperCase)
If oCtrl.Name = "txtKeys" Then
Set oRng = ActiveDocument.SelectContentControlsByTag("Keys").Item(1).Range
oRng.Text = StrConv(oCtrl.Text, vbProperCase)
oRng.Words.Last = UCase(oRng.Words.Last)
ElseIf oCtrl.Name = "txtKeys" And InStr(1, "Yet to be determined.") Then
Set oRng = ActiveDocument.SelectContentControlsByTag("Keys").Item(1).Range
oRng.Text = StrConv(oCtrl.Text, vbLowerCase)
oRng.Words.First = UCase(oRng.Words.First)
End If
Else
ActiveDocument.SelectContentControlsByTag(Replace(oCtrl.Name, "txt", "")).Item(1).Range.Text = oCtrl.Text
End If
End Select
Next oCtrl
End With
lbl_Exit:
Exit Sub
End Sub
I have a scenario where a single TextBox might have two different types of input. These being "Yet to be determined.", which is the default and then any other entry. Both are targeted to the same Content Control.
The issue that I'm having is that the "Yet to be determined." needs to be formatted as per sentence, although the other option needs to be propercase with the last word uppercase (as per previous post 'Trying to apply two types of word case formatting to TextBox').
The nearest I get is the below, which shows the default as required, but "ignores" the second formatting case altogether.
Sub FillForm()
Dim oCtrl As Control
Dim oCC As ContentControl
Dim lngIndex As Long
Dim strTC As String
Dim oRng As Range
With m_oFrm
For Each oCtrl In .Controls
Select Case TypeName(oCtrl)
Case "TextBox"
If oCtrl.Name = "txtDescription" Then
Set oCC = ActiveDocument.SelectContentControlsByTag("Description").Item(1)
oCC.Range.Text = StrConv(oCtrl.Text, vbProperCase)
If oCtrl.Name = "txtKeys" Then
Set oRng = ActiveDocument.SelectContentControlsByTag("Keys").Item(1).Range
oRng.Text = StrConv(oCtrl.Text, vbProperCase)
oRng.Words.Last = UCase(oRng.Words.Last)
ElseIf oCtrl.Name = "txtKeys" And InStr(1, "Yet to be determined.") Then
Set oRng = ActiveDocument.SelectContentControlsByTag("Keys").Item(1).Range
oRng.Text = StrConv(oCtrl.Text, vbLowerCase)
oRng.Words.First = UCase(oRng.Words.First)
End If
Else
ActiveDocument.SelectContentControlsByTag(Replace(oCtrl.Name, "txt", "")).Item(1).Range.Text = oCtrl.Text
End If
End Select
Next oCtrl
End With
lbl_Exit:
Exit Sub
End Sub