Consulting

Results 1 to 2 of 2

Thread: 'Submit' button

  1. #1
    VBAX Newbie
    Joined
    May 2021
    Posts
    1
    Location

    'Submit' button

    I have a Word form where fields have been created using Developer content controls (some fields are 'required'). Could someone please advise a block of VBA code that would disable the Submit button, and show a message box, pending completion of previously unfilled 'required' fields, and thereafter e-mailing the form from any e-mail client.

    My understanding of VBA code is at novice level.

    Any assistance would be appreciated.

    PeteB

  2. #2
    Not sure what you tried, but the following should work. It assumes your button is CommandButton1
    Change the titles of the controls to check as required

    Private Sub CommandButton1_Click()
    Dim oCC As ContentControl
        For Each oCC In ActiveDocument.ContentControls
            Select Case oCC.Title
                Case "Field 1 Title", "Field 2 Title"   'The titles of the required controls separated by commas
                    If oCC.ShowingPlaceholderText = True Then
                        oCC.Range.Select
                        MsgBox "Complete the field", vbCritical
                        Exit Sub
                    End If
                Case Else
            End Select
        Next oCC
        'rest of submit button code goes here
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •