PC Review


Reply
Thread Tools Rate Thread

Automatically naming documents with data in form fields?

 
 
=?Utf-8?B?QU1H?=
Guest
Posts: n/a
 
      20th Feb 2006
I want to save documents using data that I have entered in form fields as the
title.
 
Reply With Quote
 
 
 
 
Jay Freedman
Guest
Posts: n/a
 
      20th Feb 2006
On Mon, 20 Feb 2006 08:05:27 -0800, AMG
<(E-Mail Removed)> wrote:

>I want to save documents using data that I have entered in form fields as the
>title.


You'll need a macro to do that. Because you've given almost no details
about your documents, it's hard to recommend what should be in the
macro. At a minimum you'll need a statement like this:

ActiveDocument.SaveAs FileName:= _
ActiveDocument.FormFields("CaseName").Result & ".doc"

but replace "CaseName" with the actual name of the form field
containing the text that forms the first part of the file name.

There are a lot of other things to think about. For instance:

- If you want the file to be saved in a folder other than the one
listed as the Documents folder in Tools > Options > File Locations,
you'll have to put that path into the FileName expression.

- You'll have to check the field result to make sure it isn't empty
and doesn't contain any characters that aren't legal in a file name.

- You'll need error handling in case the folder isn't available or
something else unexpected happens.

- If your macro is named FileSaveAs, it will run instead of the
built-in SaveAs command (see
http://www.word.mvps.org/FAQs/Macros...tSavePrint.htm). That
may or may not be what you want to do.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Reply With Quote
 
=?Utf-8?B?QU1H?=
Guest
Posts: n/a
 
      22nd Feb 2006
I have the form fields named text1, text2, etc. I want to save the file as
text1 text2 (today's date) unit text7.doc

"Jay Freedman" wrote:

> On Mon, 20 Feb 2006 08:05:27 -0800, AMG
> <(E-Mail Removed)> wrote:
>
> >I want to save documents using data that I have entered in form fields as the
> >title.

>
> You'll need a macro to do that. Because you've given almost no details
> about your documents, it's hard to recommend what should be in the
> macro. At a minimum you'll need a statement like this:
>
> ActiveDocument.SaveAs FileName:= _
> ActiveDocument.FormFields("CaseName").Result & ".doc"
>
> but replace "CaseName" with the actual name of the form field
> containing the text that forms the first part of the file name.
>
> There are a lot of other things to think about. For instance:
>
> - If you want the file to be saved in a folder other than the one
> listed as the Documents folder in Tools > Options > File Locations,
> you'll have to put that path into the FileName expression.
>
> - You'll have to check the field result to make sure it isn't empty
> and doesn't contain any characters that aren't legal in a file name.
>
> - You'll need error handling in case the folder isn't available or
> something else unexpected happens.
>
> - If your macro is named FileSaveAs, it will run instead of the
> built-in SaveAs command (see
> http://www.word.mvps.org/FAQs/Macros...tSavePrint.htm). That
> may or may not be what you want to do.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the
> newsgroup so all may benefit.
>

 
Reply With Quote
 
Jay Freedman
Guest
Posts: n/a
 
      22nd Feb 2006
In that case, you want code like this, which constructs the file name in a
string, piece by piece, and then uses the string to save the file:

Dim myFile As String
With ActiveDocument.FormFields
myFile = .Item("Text1").Result
myFile = myFile & " " & _
.Item("Text2").Result
myFile = myFile & " " & _
Format(Now, "dd MMM yyyy")
myFile = myFile & " unit " & _
.Item("Text7").Result
myFile = myFile & ".doc"
End With
ActiveDocument.SaveAs FileName:=myFile

You can choose the format you want for the date, but be careful not to put
in any characters that aren't valid in a file name.

All the other considerations I listed earlier still need to be taken care
of.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

AMG wrote:
> I have the form fields named text1, text2, etc. I want to save the
> file as text1 text2 (today's date) unit text7.doc
>
> "Jay Freedman" wrote:
>
>> On Mon, 20 Feb 2006 08:05:27 -0800, AMG
>> <(E-Mail Removed)> wrote:
>>
>>> I want to save documents using data that I have entered in form
>>> fields as the title.

>>
>> You'll need a macro to do that. Because you've given almost no
>> details about your documents, it's hard to recommend what should be
>> in the macro. At a minimum you'll need a statement like this:
>>
>> ActiveDocument.SaveAs FileName:= _
>> ActiveDocument.FormFields("CaseName").Result & ".doc"
>>
>> but replace "CaseName" with the actual name of the form field
>> containing the text that forms the first part of the file name.
>>
>> There are a lot of other things to think about. For instance:
>>
>> - If you want the file to be saved in a folder other than the one
>> listed as the Documents folder in Tools > Options > File Locations,
>> you'll have to put that path into the FileName expression.
>>
>> - You'll have to check the field result to make sure it isn't empty
>> and doesn't contain any characters that aren't legal in a file name.
>>
>> - You'll need error handling in case the folder isn't available or
>> something else unexpected happens.
>>
>> - If your macro is named FileSaveAs, it will run instead of the
>> built-in SaveAs command (see
>> http://www.word.mvps.org/FAQs/Macros...tSavePrint.htm). That
>> may or may not be what you want to do.
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the
>> newsgroup so all may benefit.



 
Reply With Quote
 
=?Utf-8?B?QU1H?=
Guest
Posts: n/a
 
      12th Mar 2006
That worked beautifully! However, I have more than one template and would
like to automatically save the document in a particular file, depending on
which template I am using. For example, any document made with template BAM
would be saved in a file named "Bay Area Mobile" using data from the form
fields as its title.

"Jay Freedman" wrote:

> In that case, you want code like this, which constructs the file name in a
> string, piece by piece, and then uses the string to save the file:
>
> Dim myFile As String
> With ActiveDocument.FormFields
> myFile = .Item("Text1").Result
> myFile = myFile & " " & _
> .Item("Text2").Result
> myFile = myFile & " " & _
> Format(Now, "dd MMM yyyy")
> myFile = myFile & " unit " & _
> .Item("Text7").Result
> myFile = myFile & ".doc"
> End With
> ActiveDocument.SaveAs FileName:=myFile
>
> You can choose the format you want for the date, but be careful not to put
> in any characters that aren't valid in a file name.
>
> All the other considerations I listed earlier still need to be taken care
> of.
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
> AMG wrote:
> > I have the form fields named text1, text2, etc. I want to save the
> > file as text1 text2 (today's date) unit text7.doc
> >
> > "Jay Freedman" wrote:
> >
> >> On Mon, 20 Feb 2006 08:05:27 -0800, AMG
> >> <(E-Mail Removed)> wrote:
> >>
> >>> I want to save documents using data that I have entered in form
> >>> fields as the title.
> >>
> >> You'll need a macro to do that. Because you've given almost no
> >> details about your documents, it's hard to recommend what should be
> >> in the macro. At a minimum you'll need a statement like this:
> >>
> >> ActiveDocument.SaveAs FileName:= _
> >> ActiveDocument.FormFields("CaseName").Result & ".doc"
> >>
> >> but replace "CaseName" with the actual name of the form field
> >> containing the text that forms the first part of the file name.
> >>
> >> There are a lot of other things to think about. For instance:
> >>
> >> - If you want the file to be saved in a folder other than the one
> >> listed as the Documents folder in Tools > Options > File Locations,
> >> you'll have to put that path into the FileName expression.
> >>
> >> - You'll have to check the field result to make sure it isn't empty
> >> and doesn't contain any characters that aren't legal in a file name.
> >>
> >> - You'll need error handling in case the folder isn't available or
> >> something else unexpected happens.
> >>
> >> - If your macro is named FileSaveAs, it will run instead of the
> >> built-in SaveAs command (see
> >> http://www.word.mvps.org/FAQs/Macros...tSavePrint.htm). That
> >> may or may not be what you want to do.
> >>
> >> --
> >> Regards,
> >> Jay Freedman
> >> Microsoft Word MVP FAQ: http://word.mvps.org
> >> Email cannot be acknowledged; please post all follow-ups to the
> >> newsgroup so all may benefit.

>
>
>

 
Reply With Quote
 
Jay Freedman
Guest
Posts: n/a
 
      12th Mar 2006
Define a string that contains the path to the folder you want, and
attach it to the beginning of the file name:

Dim myFile As String
Dim myPath As String
myPath = "C:\Bay Area Mobile\"

' this part is the same as in the previous macro
With ActiveDocument.FormFields
myFile = .Item("Text1").Result
myFile = myFile & " " & _
.Item("Text2").Result
myFile = myFile & " " & _
Format(Now, "dd MMM yyyy")
myFile = myFile & " unit " & _
.Item("Text7").Result
myFile = myFile & ".doc"
End With

myFile = myPath & myFile

ActiveDocument.SaveAs FileName:=myFile

In each template, change the line that assigns the value of myPath to
the proper folder for that template's documents.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Sun, 12 Mar 2006 11:05:26 -0800, AMG
<(E-Mail Removed)> wrote:

>That worked beautifully! However, I have more than one template and would
>like to automatically save the document in a particular file, depending on
>which template I am using. For example, any document made with template BAM
>would be saved in a file named "Bay Area Mobile" using data from the form
>fields as its title.
>
>"Jay Freedman" wrote:
>
>> In that case, you want code like this, which constructs the file name in a
>> string, piece by piece, and then uses the string to save the file:
>>
>> Dim myFile As String
>> With ActiveDocument.FormFields
>> myFile = .Item("Text1").Result
>> myFile = myFile & " " & _
>> .Item("Text2").Result
>> myFile = myFile & " " & _
>> Format(Now, "dd MMM yyyy")
>> myFile = myFile & " unit " & _
>> .Item("Text7").Result
>> myFile = myFile & ".doc"
>> End With
>> ActiveDocument.SaveAs FileName:=myFile
>>
>> You can choose the format you want for the date, but be careful not to put
>> in any characters that aren't valid in a file name.
>>
>> All the other considerations I listed earlier still need to be taken care
>> of.
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
>> all may benefit.
>>
>> AMG wrote:
>> > I have the form fields named text1, text2, etc. I want to save the
>> > file as text1 text2 (today's date) unit text7.doc
>> >
>> > "Jay Freedman" wrote:
>> >
>> >> On Mon, 20 Feb 2006 08:05:27 -0800, AMG
>> >> <(E-Mail Removed)> wrote:
>> >>
>> >>> I want to save documents using data that I have entered in form
>> >>> fields as the title.
>> >>
>> >> You'll need a macro to do that. Because you've given almost no
>> >> details about your documents, it's hard to recommend what should be
>> >> in the macro. At a minimum you'll need a statement like this:
>> >>
>> >> ActiveDocument.SaveAs FileName:= _
>> >> ActiveDocument.FormFields("CaseName").Result & ".doc"
>> >>
>> >> but replace "CaseName" with the actual name of the form field
>> >> containing the text that forms the first part of the file name.
>> >>
>> >> There are a lot of other things to think about. For instance:
>> >>
>> >> - If you want the file to be saved in a folder other than the one
>> >> listed as the Documents folder in Tools > Options > File Locations,
>> >> you'll have to put that path into the FileName expression.
>> >>
>> >> - You'll have to check the field result to make sure it isn't empty
>> >> and doesn't contain any characters that aren't legal in a file name.
>> >>
>> >> - You'll need error handling in case the folder isn't available or
>> >> something else unexpected happens.
>> >>
>> >> - If your macro is named FileSaveAs, it will run instead of the
>> >> built-in SaveAs command (see
>> >> http://www.word.mvps.org/FAQs/Macros...tSavePrint.htm). That
>> >> may or may not be what you want to do.
>> >>
>> >> --
>> >> Regards,
>> >> Jay Freedman
>> >> Microsoft Word MVP FAQ: http://word.mvps.org
>> >> Email cannot be acknowledged; please post all follow-ups to the
>> >> newsgroup so all may benefit.

>>
>>
>>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically fill in some fields in data entry form Deb Microsoft Access 1 17th Aug 2009 03:05 PM
Creating/Naming a folder using multiple form fields RLConger@gmail.com Microsoft Access Queries 2 29th Jan 2009 09:39 PM
naming documents automatically Millie Microsoft Word Document Management 3 3rd Nov 2008 09:38 AM
Naming Conventions for Form Fields =?Utf-8?B?Q0xKaW5WQQ==?= Microsoft Frontpage 11 9th Feb 2005 01:59 PM
link fields to input data from one form to another automatically =?Utf-8?B?Q29sbGVnZXN0dWRlbnQ=?= Microsoft Access Database Table Design 0 10th Nov 2004 05:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:20 PM.