Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2005

Tip: Looking for answers? Try searching our database.

formfield help

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeremy - 02 Jun 2005 06:45 GMT
Looks like this:

Invoice # :  {MACROBUTTON NoMacro [Click Here]}

How do I make this a "formfield" or something and create a macro that will
take the value that's entered by the user into the "Invoice" box (using
formula above) and automatically use the invoice number as the document name
when I run my save-as macro?

Somebody provided me this formula, but I'm just not to sure how to use it:

' jer2 Macro
' Macro created 5/26/2005 by Jeremy
'
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
   ' you can get the name from a formfield by identifying it by name
   ' in this case you'll have to change "ProjectName" to the name of your
FormField
  .Name = "C:\invoices\new invoices" &
ActiveDocument.FormFields("ProjectName").Range.Text
  .Show
End With

End Sub

And for the record, my saveas macro looks like this:

Sub saveas()
'
' saveas Macro
' Macro created 2005 May 30 by Jeremy Shaw
'
Dim oDlg As Dialog
Set oDlg = Dialogs(wdDialogFileSaveAs)
With oDlg
  .Name = "c:\invoices\new invoices" ' the directory
  .Show
End With

End Sub
Doug Robbins - 04 Jun 2005 07:04 GMT
The easiest thing is to use a text formfield into which the user will enter
the invoice number.  If however, you do not want/cannot tolerate the
document being protected for forms, you can get away with using a bookmark
IF, when creating the bookmark, the selection includes a space both before
and after the [Click Here] so that with the display of bookmarks turned on,
you see

[ [Click Here] ]

where the outer [ ] are the bookmark markers.

The you can use

Dim Invoice as String

Invoice = Trim(ActiveDocument.Bookmarks("bookmarkname").Range.Text

If you do not have the spaces before and after, when the user enters the
invoice number, the bookmark will be deleted from the document and the code
will not work.

The snippet of someone else's code that you posted was created for the use
of a formfield in a protected document, though it is probably better to use:

ActiveDocument.FormFields("ProjectName").Result

Note, you do not have to show the FileSaveAs dialog if you do not want the
user to have the ability to change the path or filename.  Just use the
ActiveDocument.SaveAs command, supplying the necessary path and filename to
it, such as

ActiveDocument.SaveAs "c:\Invoices\" & Invoice

Where Invoice is declared and populated as first mentioned above.

For more on forms, see:
Please Fill Out This Form
Part 1: Create professional looking forms in Word
http://www.computorcompanion.com/LPMArticle.asp?ID=22

Part 2: Adding Automation to your Word forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=46

Part 3: Learn more VBA (macros) to automate your forms.
http://www.computorcompanion.com/LPMArticle.asp?ID=119

Part 4: Use custom dialog boxes in your Word forms
http://www.computorcompanion.com/LPMArticle.asp?ID=127

Part 5: Connect your AutoForm to a database to save input time and keep
better records!
http://www.computorcompanion.com/LPMArticle.asp?ID=136

Signature

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

> Looks like this:
>
[quoted text clipped - 38 lines]
>
> End Sub
Jeremy - 05 Jun 2005 21:34 GMT
Ok...the saga continues....

Eventually I'm going to be a pro at all this programming stuff.

Anyways....I've created a macro that automatically saves the current file to
a specified directory without displaying the saveas dialog box because I do
not want the user to have the option of changing the field....and it works
great.

Now I've gone one step further and created a custom dialog box that pops up
when this save macro has been activated and it basically confirms that they
have saved their file.  I'm trying to use two command buttons on my form.
I've got one working that is just an "OK" button...that basically just hides
the form and returns to the document when clicked.  The second one that I'm
trying to use is a command button that will close down MS Word and return to
windows desktop.  I can't seem to figure out the code.  I found one but it
actually closes down all programs including windows.

Any suggestions?

Now...my original problem also still exists....I've been playing with text
boxes and bookmarks and I'm yet to figure out how to make a field of some
kind that automatically enters itself as the filename when I run the save
macro.

> The easiest thing is to use a text formfield into which the user will
> enter the invoice number.  If however, you do not want/cannot tolerate the
[quoted text clipped - 93 lines]
>>
>> End Sub
Jeremy - 05 Jun 2005 21:57 GMT
And to clarify....my save macro looks like this:

Sub save()
'
' save Macro
' Macro created 6/5/2005 by Jeremy
'
ActiveDocument.SaveAs "C:\Jer-Pictures\My Pictures\motorcycles"

UserForm1.Show

End Sub

So....I'm having difficulty understanding how to edit the save as line to
include the name with the path.   I've got a text input form field on my
page called invoice and I've created a bookmark around it also called
invoice.  So what do I need to add to this save macro to grab the info from
the invoice field, and use that as the filename.  (Users will obviously be
punching in a invoice number into this field and I want the file to
automatically save as the invoice number.)

Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.