Easy One? - Input Box with Two Fields in Word Macro?

In Word, is there a macro code or a way to create an Input Box with two fields for two instances of input data like you can in Filemaker, for example?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Not really, as far as I know, but you can ask the user to put in a delimiter of some sort. For example:

Public Sub InputBox2Params()
    Dim sInputVal As String
    Dim sValue1 As String, sValue2 As String
    Dim iOctothorpPosition As Integer
    sInputVal = InputBox(Prompt:="Please type in two values, one in front of the octothorp (#) and the other after it.", _
                                    Title:="Type in two values", Default:=" # ")
    iOctothorpPosition = InStr(1, sInputVal, "#", vbTextCompare)
    sValue1 = Trim(Mid(sInputVal, 1, iOctothorpPosition - 1))
    sValue2 = Trim(Mid(sInputVal, iOctothorpPosition + 1))

    MsgBox "sValue1 = " & sValue1 & vbCrLf & "sValue2 = " & sValue2

End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Other alternatives are to use two succesive InputBox statements, or to employ a UserForn with two textboxes.
FWIW, in practice, I usually go with the UserForm idea that GrahamSkan mentions.
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

rvfowler2Author Commented:
Thanks, I'll look into UserForms.  Been a avery long time since I used or designed one.
For this example, create a userform and add two textboxes (named txtThingOne and txtThingTwo) and two buttons (cmdCancel and cmdOK), and put the following code behind those buttons.

Note that the code in cmdOK_Click() refers to the CDP creation routines we discussed earlier; I've included those here, too, just for completeness' sake. Hope this helps.
Private Sub cmdCancel_Click()
    MsgBox prompt:="Note: No values have been saved for Thing One or Thing Two.", Buttons:=vbOKCancel & vbCritical, Title:="Missing Data"
    Unload Me
End Sub

Private Sub cmdOK_Click()
    Dim bGotItAll As Boolean
    Dim sThingOne As String, sThingTwo As String
    sThingOne = Trim(txtThingOne.Value)
    sThingTwo = Trim(txtThingTwo.Value)
    bGotItAll = False
    If sThingOne = "" Then
        MsgBox prompt:="Please enter something into Thing One.", Buttons:=vbOKCancel & vbCritical, Title:="Missing Data"
    ElseIf sThingTwo = "" Then
        MsgBox prompt:="Please enter something into Thing Two.", Buttons:=vbOKCancel & vbCritical, Title:="Missing Data"
        bGotItAll = True
    End If
    If bGotItAll Then
        CreateAndPopulateOneCDP "cdpThingOne", sThingOne
        CreateAndPopulateOneCDP "cdpThingTwo", sThingTwo
        Unload Me
    End If ' bGotItAll
End Sub

Public Sub CreateAndPopulateOneCDP(ByVal psCdpName As String, ByVal psCdpValue As String)
        If CdpExists(psCdpName) Then
            ActiveDocument.CustomDocumentProperties(psCdpName) = psCdpValue
        Else ' CdpExists(psCdpName) = False
            ActiveDocument.CustomDocumentProperties.Add _
                Name:=psCdpName, LinkToContent:=False, Value:=psCdpValue, _
        End If ' CdpExists(psCdpName)
End Sub ' CreateAndPopulateOneCDP(ByVal psCdpName As String, ByVal psCdpValue As String)
Public Function CdpExists(ByVal CdpName As String) As Boolean
Dim xx As DocumentProperty
    For Each xx In ActiveDocument.CustomDocumentProperties
            If LCase(xx.Name) = LCase(CdpName) Then
                CdpExists = True
                Exit Function
            End If ' xx.Name <> CdpName
    Next xx
    CdpExists = False
End Function

Open in new window

rvfowler2Author Commented:
Thanks, it does help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Word

From novice to tech pro — start learning today.