Reply
 
Thread Tools Display Modes
  #1   Report Post  
jeffy
 
Posts: n/a
Default Creating Filename from Form Data

I have created a Doc Template in Word, and I would like to extract data from
Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having difficulty
modifying it successfully to extract the data from my form fields. Is there
something I am issing?
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

jeffy wrote:
I have created a Doc Template in Word, and I would like to extract
data from Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having
difficulty modifying it successfully to extract the data from my form
fields. Is there something I am issing?


There's really no way for us to tell whether you're missing something unless
you post the relevant code for us to look at. Also explain exactly what does
happen vs. what you expect to happen. Do you get the wrong filename, or no
filename, or do you get an error? If there's an error message, quote the
message exactly, and tell us which line of code is highlighted in the editor
when that happens.

Before you go to that trouble, double-check that the field names you use in
the code exactly match the spelling of the "bookmark names" in the
Properties dialogs of the fields in the form.

If you can remember, also tell us where you got the macro example so we can
look at that.

Finally, this topic would be more appropriate in one of the programming
newsgroups such as microsoft.public.word.vba.beginners.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


  #3   Report Post  
jeffy
 
Posts: n/a
Default

I have attached the code that I am attempting to use.

When I insert it into my Template, I get a blank filename when I attempt to
save. My bookmarks are checjked and double checked.

Sub FileSave()
With Application.Dialogs(wdDialogFileSaveAs)
.Name = Model & " SN" & Serial & " " & RNumber & " "
& Customer
.Show
End With
End Sub


"Jay Freedman" wrote:

jeffy wrote:
I have created a Doc Template in Word, and I would like to extract
data from Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having
difficulty modifying it successfully to extract the data from my form
fields. Is there something I am issing?


There's really no way for us to tell whether you're missing something unless
you post the relevant code for us to look at. Also explain exactly what does
happen vs. what you expect to happen. Do you get the wrong filename, or no
filename, or do you get an error? If there's an error message, quote the
message exactly, and tell us which line of code is highlighted in the editor
when that happens.

Before you go to that trouble, double-check that the field names you use in
the code exactly match the spelling of the "bookmark names" in the
Properties dialogs of the fields in the form.

If you can remember, also tell us where you got the macro example so we can
look at that.

Finally, this topic would be more appropriate in one of the programming
newsgroups such as microsoft.public.word.vba.beginners.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



  #4   Report Post  
Jay Freedman
 
Posts: n/a
Default

Should I assume that Model, Serial, RNumber, and Customer are the names of
the form fields -- what you see in the Bookmark box in the Properties
dialogs?

VBA looks at those words and assumes that they're VBA variables, not field
names. And since you haven't assigned any value to those "variables",
they're empty (that's the default value for Variant type variables).

Instead, you need to declare the variables in Dim statements and assign the
contents of the fields to those variables. It works like this:

Sub FileSave()
Dim MyModel As String, MySerial As String
Dim MyNumber As String, MyCustomer As String

MyModel = ActiveDocument.FormFields("Model").Result
MySerial = ActiveDocument.FormFields("Serial").Result
MyNumber = ActiveDocument.FormFields("RNumber").Result
MyCustomer = ActiveDocument.FormFields("Customer").Result

With Application.Dialogs(wdDialogFileSaveAs)
.Name = MyModel & " SN" & MySerial & " " & _
MyNumber & " " & MyCustomer
.Show
End With
End Sub

A properly designed macro would also check that the fields aren't empty, and
possibly validate them (for example, to make sure the serial number contains
7 digits and no other characters, or whatever the rules are).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

jeffy wrote:
I have attached the code that I am attempting to use.

When I insert it into my Template, I get a blank filename when I
attempt to save. My bookmarks are checjked and double checked.

Sub FileSave()
With Application.Dialogs(wdDialogFileSaveAs)
.Name = Model & " SN" & Serial & " " &
RNumber & " " & Customer
.Show
End With
End Sub


"Jay Freedman" wrote:

jeffy wrote:
I have created a Doc Template in Word, and I would like to extract
data from Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having
difficulty modifying it successfully to extract the data from my
form fields. Is there something I am issing?


There's really no way for us to tell whether you're missing
something unless you post the relevant code for us to look at. Also
explain exactly what does happen vs. what you expect to happen. Do
you get the wrong filename, or no filename, or do you get an error?
If there's an error message, quote the message exactly, and tell us
which line of code is highlighted in the editor when that happens.

Before you go to that trouble, double-check that the field names you
use in the code exactly match the spelling of the "bookmark names"
in the Properties dialogs of the fields in the form.

If you can remember, also tell us where you got the macro example so
we can look at that.

Finally, this topic would be more appropriate in one of the
programming newsgroups such as microsoft.public.word.vba.beginners.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



  #5   Report Post  
jeffy
 
Posts: n/a
Default

Your code looks great. I have inserted it as a macro, and double checked all
of the Bookmarks/Variable assignments against my template to be sure they are
correct.

Now it seems to do the standard First Line of Text filename when I select
Save As.

I appreciate your patience as I stretch my wings here.

Regards,

Jeff

"Jay Freedman" wrote:

Should I assume that Model, Serial, RNumber, and Customer are the names of
the form fields -- what you see in the Bookmark box in the Properties
dialogs?

VBA looks at those words and assumes that they're VBA variables, not field
names. And since you haven't assigned any value to those "variables",
they're empty (that's the default value for Variant type variables).

Instead, you need to declare the variables in Dim statements and assign the
contents of the fields to those variables. It works like this:

Sub FileSave()
Dim MyModel As String, MySerial As String
Dim MyNumber As String, MyCustomer As String

MyModel = ActiveDocument.FormFields("Model").Result
MySerial = ActiveDocument.FormFields("Serial").Result
MyNumber = ActiveDocument.FormFields("RNumber").Result
MyCustomer = ActiveDocument.FormFields("Customer").Result

With Application.Dialogs(wdDialogFileSaveAs)
.Name = MyModel & " SN" & MySerial & " " & _
MyNumber & " " & MyCustomer
.Show
End With
End Sub

A properly designed macro would also check that the fields aren't empty, and
possibly validate them (for example, to make sure the serial number contains
7 digits and no other characters, or whatever the rules are).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

jeffy wrote:
I have attached the code that I am attempting to use.

When I insert it into my Template, I get a blank filename when I
attempt to save. My bookmarks are checjked and double checked.

Sub FileSave()
With Application.Dialogs(wdDialogFileSaveAs)
.Name = Model & " SN" & Serial & " " &
RNumber & " " & Customer
.Show
End With
End Sub


"Jay Freedman" wrote:

jeffy wrote:
I have created a Doc Template in Word, and I would like to extract
data from Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having
difficulty modifying it successfully to extract the data from my
form fields. Is there something I am issing?

There's really no way for us to tell whether you're missing
something unless you post the relevant code for us to look at. Also
explain exactly what does happen vs. what you expect to happen. Do
you get the wrong filename, or no filename, or do you get an error?
If there's an error message, quote the message exactly, and tell us
which line of code is highlighted in the editor when that happens.

Before you go to that trouble, double-check that the field names you
use in the code exactly match the spelling of the "bookmark names"
in the Properties dialogs of the fields in the form.

If you can remember, also tell us where you got the macro example so
we can look at that.

Finally, this topic would be more appropriate in one of the
programming newsgroups such as microsoft.public.word.vba.beginners.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org






  #6   Report Post  
jeffy
 
Posts: n/a
Default

Got it!!! I am using FileSave not FileSaveAs.

Works Great...Thanks again!!!

Jeff

"jeffy" wrote:

Your code looks great. I have inserted it as a macro, and double checked all
of the Bookmarks/Variable assignments against my template to be sure they are
correct.

Now it seems to do the standard First Line of Text filename when I select
Save As.

I appreciate your patience as I stretch my wings here.

Regards,

Jeff

"Jay Freedman" wrote:

Should I assume that Model, Serial, RNumber, and Customer are the names of
the form fields -- what you see in the Bookmark box in the Properties
dialogs?

VBA looks at those words and assumes that they're VBA variables, not field
names. And since you haven't assigned any value to those "variables",
they're empty (that's the default value for Variant type variables).

Instead, you need to declare the variables in Dim statements and assign the
contents of the fields to those variables. It works like this:

Sub FileSave()
Dim MyModel As String, MySerial As String
Dim MyNumber As String, MyCustomer As String

MyModel = ActiveDocument.FormFields("Model").Result
MySerial = ActiveDocument.FormFields("Serial").Result
MyNumber = ActiveDocument.FormFields("RNumber").Result
MyCustomer = ActiveDocument.FormFields("Customer").Result

With Application.Dialogs(wdDialogFileSaveAs)
.Name = MyModel & " SN" & MySerial & " " & _
MyNumber & " " & MyCustomer
.Show
End With
End Sub

A properly designed macro would also check that the fields aren't empty, and
possibly validate them (for example, to make sure the serial number contains
7 digits and no other characters, or whatever the rules are).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

jeffy wrote:
I have attached the code that I am attempting to use.

When I insert it into my Template, I get a blank filename when I
attempt to save. My bookmarks are checjked and double checked.

Sub FileSave()
With Application.Dialogs(wdDialogFileSaveAs)
.Name = Model & " SN" & Serial & " " &
RNumber & " " & Customer
.Show
End With
End Sub


"Jay Freedman" wrote:

jeffy wrote:
I have created a Doc Template in Word, and I would like to extract
data from Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having
difficulty modifying it successfully to extract the data from my
form fields. Is there something I am issing?

There's really no way for us to tell whether you're missing
something unless you post the relevant code for us to look at. Also
explain exactly what does happen vs. what you expect to happen. Do
you get the wrong filename, or no filename, or do you get an error?
If there's an error message, quote the message exactly, and tell us
which line of code is highlighted in the editor when that happens.

Before you go to that trouble, double-check that the field names you
use in the code exactly match the spelling of the "bookmark names"
in the Properties dialogs of the fields in the form.

If you can remember, also tell us where you got the macro example so
we can look at that.

Finally, this topic would be more appropriate in one of the
programming newsgroups such as microsoft.public.word.vba.beginners.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org




  #7   Report Post  
Posted to microsoft.public.word.docmanagement
Andrew Andrew is offline
external usenet poster
 
Posts: 48
Default Creating Filename from Form Data

can a similar macro be used to create file names from the files' "properties"
data?
--
agibson


"Jay Freedman" wrote:

Should I assume that Model, Serial, RNumber, and Customer are the names of
the form fields -- what you see in the Bookmark box in the Properties
dialogs?

VBA looks at those words and assumes that they're VBA variables, not field
names. And since you haven't assigned any value to those "variables",
they're empty (that's the default value for Variant type variables).

Instead, you need to declare the variables in Dim statements and assign the
contents of the fields to those variables. It works like this:

Sub FileSave()
Dim MyModel As String, MySerial As String
Dim MyNumber As String, MyCustomer As String

MyModel = ActiveDocument.FormFields("Model").Result
MySerial = ActiveDocument.FormFields("Serial").Result
MyNumber = ActiveDocument.FormFields("RNumber").Result
MyCustomer = ActiveDocument.FormFields("Customer").Result

With Application.Dialogs(wdDialogFileSaveAs)
.Name = MyModel & " SN" & MySerial & " " & _
MyNumber & " " & MyCustomer
.Show
End With
End Sub

A properly designed macro would also check that the fields aren't empty, and
possibly validate them (for example, to make sure the serial number contains
7 digits and no other characters, or whatever the rules are).

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org

jeffy wrote:
I have attached the code that I am attempting to use.

When I insert it into my Template, I get a blank filename when I
attempt to save. My bookmarks are checjked and double checked.

Sub FileSave()
With Application.Dialogs(wdDialogFileSaveAs)
.Name = Model & " SN" & Serial & " " &
RNumber & " " & Customer
.Show
End With
End Sub


"Jay Freedman" wrote:

jeffy wrote:
I have created a Doc Template in Word, and I would like to extract
data from Form fields and create a filename.

A Macro example I have found do not seem to work, OR I am having
difficulty modifying it successfully to extract the data from my
form fields. Is there something I am issing?

There's really no way for us to tell whether you're missing
something unless you post the relevant code for us to look at. Also
explain exactly what does happen vs. what you expect to happen. Do
you get the wrong filename, or no filename, or do you get an error?
If there's an error message, quote the message exactly, and tell us
which line of code is highlighted in the editor when that happens.

Before you go to that trouble, double-check that the field names you
use in the code exactly match the spelling of the "bookmark names"
in the Properties dialogs of the fields in the form.

If you can remember, also tell us where you got the macro example so
we can look at that.

Finally, this topic would be more appropriate in one of the
programming newsgroups such as microsoft.public.word.vba.beginners.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org




Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a data update request form datagrl Microsoft Word Help 0 July 5th 05 05:31 PM
Data Form button Carla Bradley Mailmerge 5 April 26th 05 07:14 PM
Can you convert regular text in a table into form field data easil Martin_of_Uxbridge Microsoft Word Help 1 April 24th 05 11:55 AM
Same Form letter different Data Base AlohaFred Microsoft Word Help 1 April 9th 05 01:11 AM
Enter data in 1 text form field & have multiple locations fill Lee Microsoft Word Help 1 March 16th 05 10:56 PM


All times are GMT +1. The time now is 04:33 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"