Saving Form Under A Specific Name

D

DA

Greetings "The Pro"

By the sound of it you want to intercept the action of
the user selecting "Save" or "Save As.."

You can do this by creating two routines as follows.
Change the "MyField" reference to the name of the fields
on your form :

-----------
Sub FileSave()
With ActiveDocument
..SaveAs FileName:=.FormFields("MyField").Result
End With
End Sub

Sub FileSaveAs()
<code>...
End Sub
------------

Best of luck,
Dennis
-----Original Message-----
I have a form and I wish, if possible, that when the
user clicks the 'save' / 'save as' / 'close' button it
automatically takes the value of one and if posible two
fields and use them as the default file name. For example
theres a field for the name and a filed for a date so
when the 'save as' prompt appears it will use *name*
*date*.doc automatically as the file name. If theres also
an option for the user not being able to edit this
default value by accidentally chaning it on the 'file
name:' text box on the 'save as' dailog window that would
be great.
 
C

Chad DeMeyer

With ActiveDocument
.SaveAs FileName:=.FormFields("Name").Result & " " &
..FormFields("Date").Result & ".doc"
End With

Notes:
- Perhaps it was only missing in your post and not in your code, but you
need the dot (.) before SaveAs in the indented line above.
- You should concatenate ".doc" to the tail end of the filename to ensure
that it remains useable in Word.
- In order for the above to work, the two fields it references must be
explicitly named "Name" and "Date" in the document. Double-click each field
(with forms protection off) to display the Text Form Field Options dialog
and specify "Name" or "Date", as appropriate, as the Bookmark.

cjd
 
D

DA

As Chad already suggested, you needed to put the "." in
front of the SaveAs, plus you need to ensure that the
name of your field is represented on your form.

My apologies, I noticed in my first post I actually had a
spelling mistake by placing two ".." in front of the
code.

The "." is placed in front of the commands because in the
sample I gave you I used a "With"-"End With" statement.
It's a method commonly used to reduce clutter in your
code when performing a series of actions on the same
object. I you want to remove the "With ActiveDocument"
from the code you then have to place "ActiveDocument" in
front of all other commands such as the .SaveAs
and .FormFields. If you're still unsure about all this,
have a read of the online Help that comes with VBA.

You do not need to run the macro on exit. By naming the
macro FileSave or FileSaveAs, you tell Word to intercept
those actions and run your code whenever the user selects
those menu actions.

The macro will take the value of your form field and use
it as the filename. It's good practice, but the SaveAs
doesn't need the .doc appended to the end, since Word
will do that automatically if your active document is in
word format.


Dennis


-----Original Message-----
Do I have to run a macro on exit on the field which
contains the value for the 'FileName'?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top