none
Submit Button RRS feed

  • Question

  • I have a Word 2010 template. It is just a template not a user word form. When the user completes the fill-in form, I would like to have a Submit button. The Submit button will do the following: Before it Saves, it will verify two specific fields are keyed in. The fields are a legacy field and the name of the field are Date and SelectOne. So if this field is not filled in, the form will not save and will give a message to fill in this field and takes you to that specific field. After verifiying I want to save the form and also save as a pdf. For saving location, I will type the path of the location where all users will have access to the folder.  I know this is a lot.  Just hoping to make some people's dreams a reality.  I hope it can be done.  Your help is much appreciated!!
    Friday, February 10, 2017 6:52 PM

All replies

  • The code would be as follows, however see your other thread which covers other issues


    Sub SaveForm()
    'Graham Mayor - http://www.gmayor.com - Last updated - 11/02/2017
    Dim strName As String
    Const strPath As String = "C:\Path\"
        With ActiveDocument.FormFields("Date")
            If .Result = "" Then
                MsgBox "Enter the date!"
                .Select
                Exit Sub
            End If
        End With
        With ActiveDocument.FormFields("SelectOne")
            If .Result = "" Then
                MsgBox "Enter the SelectOne value!"
                .Select
                Exit Sub
            End If
        End With
        strName = Format(ActiveDocument.FormFields("Date").Result, "dd.mm.yyyy_")
        strName = strName & ActiveDocument.FormFields("SelectOne").Result
        ActiveDocument.SaveAs2 FileName:=strPath & strName & ".docx", Fileformat:=12
        SaveAsPDF
    lbl_Exit:
        Exit Sub
    End Sub
    
    Private Sub SaveAsPDF()
    'Graham Mayor - http://www.gmayor.com - Last updated - 11/02/2017
    Dim strDocName As String
    Dim strPath As String
    Dim intPos As Integer
    Start:
        'Find position of extension in filename
        strDocName = ActiveDocument.Name
        strPath = ActiveDocument.Path & "\"
        intPos = InStrRev(strDocName, ".")
        If intPos = 0 Then
            ActiveDocument.Save
            GoTo Start
        End If
        strDocName = Left(strDocName, intPos - 1)
        strDocName = strPath & strDocName & ".pdf"
    
        ActiveDocument.ExportAsFixedFormat OutputFilename:=strDocName, _
                                           ExportFormat:=wdExportFormatPDF, _
                                           OpenAfterExport:=False, _
                                           OptimizeFor:=wdExportOptimizeForPrint, _
                                           Range:=wdExportAllDocument, From:=1, to:=1, _
                                           Item:=wdExportDocumentContent, _
                                           IncludeDocProps:=True, _
                                           KeepIRM:=True, _
                                           CreateBookmarks:=wdExportCreateHeadingBookmarks, _
                                           DocStructureTags:=True, _
                                           BitmapMissingFonts:=True, _
                                           UseISO19005_1:=False
    lbl_Exit:
        Exit Sub
    End Sub
    
    



    Graham Mayor - Word MVP
    www.gmayor.com

    Saturday, February 11, 2017 5:51 AM
  • This works great except for the Select One field.  This is actually legacy drop down field.  I'm assuming it isn't listed as a field form and why that part of the code isn't working? 
    Monday, February 13, 2017 7:29 PM
  • The most likely reason is that the name of the legacy field is not SelectOne. Check the field properties.

    Graham Mayor - Word MVP
    www.gmayor.com

    Tuesday, February 14, 2017 4:47 AM
  • The drop down field is called SelectOne on the properties.  This is the only one that doesn't work. 

    With ActiveDocument.FormFields("SelectOne")
            If .Result = "" Then
                MsgBox "Select a value from the dropdown field first!"
                Selection.GoTo what:=wdGoToBookmark, Name:="SelectOne"
                Exit Sub
            End If
        End With

    Tuesday, February 14, 2017 3:11 PM
  • That's not what I wrote. However, with a legacy dropdown form field the result should never be "" and therefore that part of the code is superfluous. Are you sure you used a legacy dropdown formfield?

    Graham Mayor - Word MVP
    www.gmayor.com

    Wednesday, February 15, 2017 8:03 AM