formfield help

J

Jeremy

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
 
D

Doug Robbins

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




--
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
Jeremy said:
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 hat'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
 
J

Jeremy

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.



Doug Robbins said:
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




--
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
Jeremy said:
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 hat'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
 
J

Jeremy

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.
 

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