Form Data into Word

raginggoat

Registered User.
Local time
Today, 13:47
Joined
Jun 23, 2009
Messages
32
I am wanting to place a command button on my forms that will take the data from each field on the form and place it into a word doc. I am having a great deal of trouble finding out how to do this.
 
firstly Why ?
and then secondandly check out super easy word - in the samples - this will allow you to cherry pick up to 254-255 fields from a table-form and use them in word -
 
I am doing it for work. A guy wants it done this way.
 
I am wanting to place a button on my forms in my current DB and write some VB code to have it put the info from the fields into Word for me.
 
Look here..
http://msdn.microsoft.com/en-us/library/aa140082(office.10).aspx
Also search on "Merge to word" .... One way uses "Bookmark" in Word. I think the full code might be in the forum someplace...
And Yes, it does come in handy when you have a standard Word document...like a contract.. and you need to fill in the blanks. You simply make a template stored as such and click your button to open word and have it populate. I use it on a bidding app I have....works fine.
 
raginggoat,

Have a look at my samples posted here

There are 2 samples, One using single bookmark and the other using multiple.
 
My forms have one column with different cities listed and next to each city i have text boxes where a price gets put in. I just want the info from those text boxes to go into word by pressing a command button on the form. My form is set up kind of like this:


City text box text box text box text box
 
raginggoat,

If your last post is in response to my post then I don't understand your statement. You don't even acknowledge my post.

Did you look at my sample?

If you did then did you try and adapt it to your situation?

or do you want someone to do it for you?
 
I did look at your post and it was helpful. I was simply trying to better explain what I am trying to do in hopes that maybe someone on here has done something more similar to my needs. I am not wanting someone to do this for me, but I do need help. I altered some of your code but I'm not sure if it is right. Here it is: I get a "user-defined type not defined error on this line: Dim objWord As Word.Application




Private Sub Command215_Click()

'Declare the follwing
Dim objWord As Word.Application

'Set word as an application and make it invisible
Set objWord = CreateObject("Word.Application")
objWord.Visible = False 'True is visible

'path and name of the template your are using.
objWord.Documents.Add ("C:\Documents and Settings\asr0245\My Documents\Grain Bids\bids form dec.doc")

'This is for the bookmark that you created in the template
objWord.ActiveDocument.Bookmarks("M_11cornc").Select

'This is the field in access that contains the data that has to be entered at the
'bookmark
objWord.Selection.Text = Forms![Form_jan-feb daily]![11cornc]


'Word (or the document that you created with the template, will now open)
objWord.Visible = True


Set objWord = Nothing



End Sub
 
"user-defined type not defined error on this line: Dim objWord As Word.Application"

Open you form in design mode, then go to your code window (Alt+F11), then to Tools / References, Select your version of Microsoft Word Object library you will see in the attached JPG file mine is 11 (2003).
 

Attachments

  • Reference.JPG
    Reference.JPG
    59.7 KB · Views: 100
I have just had quick look at your code and I see a couple of errors;

Code:
objWord.Documents.Add ("C:\Documents and Settings\asr0245\My Documents\Grain Bids\bids form dec.doc")

This should be a template in word and not a normal document. I would also name my template bids_form_dec.dot I don't like spaces (your choice)

Code:
objWord.ActiveDocument.Bookmarks("M_11cornc").[B]Sele ct[/B]

This should be; - you had a space in the word Select

Code:
objWord.ActiveDocument.Bookmarks("M_11cornc").[B]Select[/B]
 
It works now! Now I get to create a bunch of new Word templates which makes me so excited (sarcasm in case you couldn't tell) One last question though. Since the data being put into Word from Access is a price, how can I get the number that shows up in Word to show up with 2 decimal places if it is a number like 3.00 which shows up in Word as just 3?
 
One other question I just thought of, if I have a sub-form in my main form and the command button is on the main form, will it work for sub-form fields as well or do I need to add another button to the sub-form?
 
This is the last question, I swear. How do I set it up to use multiple bookmarks in the same template for all the fields in my Access form? Do I just add more of these lines in the code?

objWord.ActiveDocument.Bookmarks("M_11cornc").Select

and

objWord.Selection.Text = Forms![jan-feb daily]![11cornc]
 
If there is nothing in a certain field, how can I tell it to display '0' in the Word doc?
 
Try the Nz function in your db... should copy over....
Nz(fieldname)
 
Answer to your questions = Read my original post. and read the code in the databases.
 

Users who are viewing this thread

Back
Top Bottom