From: johnnykunst on
I have a form which generates the filename from various drop down fields/ text fields(for extraction of text in one field, the text is split, only using PART of the entry)

I would like to populate the footer with the generated filename BEFORE the file is saved with this auto generated name.

The code I am using to create the fileneame & save with this name is (section after "Call RunSpellCheck":

Private Sub CommandButton1_Click()
If ActiveDocument.FormFields("classificationDD").Result = "ENTER REPORT CLASSIFICATION" Then
MsgBox "You forgot to fill in the REPORT CLASSIFICATION. This field MUST be filled in before you can save the document"
Exit Sub
End If
If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then
MsgBox "You forgot to fill in YOUR NAME. This field MUST be filled in before you can save the document"
Exit Sub
End If
If ActiveDocument.FormFields("Date").Result = "Monday, 01-01-2001" Then
MsgBox "You forgot to fill in the INCIDENT DATE. This field MUST be filled in before you can save the document"
Exit Sub
End If
If ActiveDocument.FormFields("Time").Result = "00.00" Then
MsgBox "You forgot to fill in the INCIDENT TIME. This field MUST be filled in before you can save the document"
Exit Sub
End If
If ActiveDocument.FormFields("Location").Result = "BLOCK & ESTATE or STREET or PARK" Then
MsgBox "You forgot to fill in the LOCATION NAME. This field MUST be filled in before you can save the document"
Exit Sub
End If
If ActiveDocument.FormFields("Reportbody").Result = "FULL REPORT- OBJECTIVE ACCOUNT INCLUDING DESCRIPTIONS OF ALL PERSONS INVOLVED" Then
MsgBox "You forgot to WRITE THE REPORT. This field MUST be filled in before you can save the document"
Exit Sub
End If
If ActiveDocument.FormFields("Keywords").Result = "40 CHARACTERS MAXIMUM" Then
MsgBox "You fill in KEYWORDS/HEADLINE. This field MUST be filled in before you can save the document"
Exit Sub
End If

Call RunSpellcheck
Dim pStr As String
pStr = "C:\Users\John\Desktop\" 'Your directory
pStr = pStr + Split( _
ActiveDocument.FormFields("nameDD").Result, "/")(0)
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("classificationDD").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("Location").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("Keywords").Result
pStr = pStr + " "
pStr = pStr + ActiveDocument.FormFields("Date").Result
ActiveDocument.SaveAs FileName:=pStr
pStr = pStr + " .doc"

Dim sCode As String
MsgBox "Your Intelligence report was saved to the central WINTEL inbox for processing & emailing. No further action is required; it is now safe to close the document"
End Sub


---
frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general
From: Doug Robbins - Word MVP on
Use a DocVariable field in the footer and some code to assign the filename
to the .Value of a variable in the document and have the code update he
DocVariable field in the footer so that the name appears there.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"johnnykunst" <user(a)msgroups.net/> wrote in message
news:O2kp0Y3#KHA.4652(a)TK2MSFTNGP06.phx.gbl...
> I have a form which generates the filename from various drop down fields/
> text fields(for extraction of text in one field, the text is split, only
> using PART of the entry)
>
> I would like to populate the footer with the generated filename BEFORE the
> file is saved with this auto generated name.
>
> The code I am using to create the fileneame & save with this name is
> (section after "Call RunSpellCheck":
>
> Private Sub CommandButton1_Click()
> If ActiveDocument.FormFields("classificationDD").Result = "ENTER REPORT
> CLASSIFICATION" Then
> MsgBox "You forgot to fill in the REPORT CLASSIFICATION. This field MUST
> be filled in before you can save the document"
> Exit Sub
> End If
> If ActiveDocument.FormFields("nameDD").Result = "ENTER NAME" Then
> MsgBox "You forgot to fill in YOUR NAME. This field MUST be filled in
> before you can save the document"
> Exit Sub
> End If
> If ActiveDocument.FormFields("Date").Result = "Monday, 01-01-2001" Then
> MsgBox "You forgot to fill in the INCIDENT DATE. This field MUST be filled
> in before you can save the document"
> Exit Sub
> End If
> If ActiveDocument.FormFields("Time").Result = "00.00" Then
> MsgBox "You forgot to fill in the INCIDENT TIME. This field MUST be filled
> in before you can save the document"
> Exit Sub
> End If
> If ActiveDocument.FormFields("Location").Result = "BLOCK & ESTATE or
> STREET or PARK" Then
> MsgBox "You forgot to fill in the LOCATION NAME. This field MUST be filled
> in before you can save the document"
> Exit Sub
> End If
> If ActiveDocument.FormFields("Reportbody").Result = "FULL REPORT-
> OBJECTIVE ACCOUNT INCLUDING DESCRIPTIONS OF ALL PERSONS INVOLVED" Then
> MsgBox "You forgot to WRITE THE REPORT. This field MUST be filled in
> before you can save the document"
> Exit Sub
> End If
> If ActiveDocument.FormFields("Keywords").Result = "40 CHARACTERS MAXIMUM"
> Then
> MsgBox "You fill in KEYWORDS/HEADLINE. This field MUST be filled in before
> you can save the document"
> Exit Sub
> End If
>
> Call RunSpellcheck
> Dim pStr As String
> pStr = "C:\Users\John\Desktop\" 'Your directory
> pStr = pStr + Split( _
> ActiveDocument.FormFields("nameDD").Result, "/")(0)
> pStr = pStr + " "
> pStr = pStr + ActiveDocument.FormFields("classificationDD").Result
> pStr = pStr + " "
> pStr = pStr + ActiveDocument.FormFields("Location").Result
> pStr = pStr + " "
> pStr = pStr + ActiveDocument.FormFields("Keywords").Result
> pStr = pStr + " "
> pStr = pStr + ActiveDocument.FormFields("Date").Result
> ActiveDocument.SaveAs FileName:=pStr
> pStr = pStr + " .doc"
>
> Dim sCode As String
> MsgBox "Your Intelligence report was saved to the central WINTEL inbox for
> processing & emailing. No further action is required; it is now safe to
> close the document"
> End Sub
>
>
> ---
> frmsrcurl: http://msgroups.net/microsoft.public.word.vba.general