473,563 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filling in Word document with Access values

30 New Member
Hi,

I've found a tutorial that shows you how to fill in Word documents with values from Access

Expand|Select|Wrap|Line Numbers
  1. 'Print customer slip for current customer.
  2. Dim appWord As Word.Application
  3. Dim doc As Word.Document
  4. 'Avoid error 429, when Word isn't open.
  5. On Error Resume Next
  6. Err.Clear
  7. 'Set appWord object variable to running instance of Word.
  8. Set appWord = GetObject(, "Word.Application")
  9. If Err.Number <> 0 Then
  10. 'If Word isn't open, create a new instance of Word.
  11. Set appWord = New Word.Application
  12. End If
  13. Set doc = appWord.Documents.Open("C:\BLANK INSTRUCTION_TEMPLATE.docx", , True)
  14. With doc
  15. .FormFields("fldCustomerID").Result = Me!CustomerID
  16. .FormFields("fldCompanyName").Result = Me!CompanyName
  17. .FormFields("fldContactName").Result = Me!ContactName
  18. .FormFields("fldContactTitle").Result = Me!ContactTitle
  19. .FormFields("fldAddress").Result = Me!Address
  20. .FormFields("fldCity").Result = Me!City
  21. .FormFields("fldRegion").Result = Me!Region
  22. .FormFields("fldPostalCode").Result = Me!PostalCode
  23. .FormFields("fldCountry").Result = Me!Country
  24. .FormFields("fldPhone").Result = Me!Phone
  25. .FormFields("fldFax").Result = Me!Fax
  26. .Visible = True
  27. .Activate
  28. End With
  29. Set doc = Nothing
  30. Set appWord = Nothing
  31. Exit Sub
  32. errHandler:
  33. MsgBox Err.Number & ": " & Err.Description
I am using Office 2007 and it doesn't seem to be working. I can see that WINWORD.exe is open in my Task Manager but the actual word document is not launching.

Does anybody know how to modify the above code to make it work with Office 2007.

Thanks,

Marat
Jul 11 '08 #1
10 9231
puppydogbuddy
1,923 Recognized Expert Top Contributor
In order for the code to work as shown, you should have placed it in a button click event on the Access Customer Form. Did you do that?

Also, verify that the file path to your word doc is correct in your code.

If the above is not the answer, place code breaks in the code and find out if your code executes to the breakpoint.
Jul 12 '08 #2
mlevit
30 New Member
In order for the code to work as shown, you should have placed it in a button click event on the Access Customer Form. Did you do that?

Also, verify that the file path to your word doc is correct in your code.

If the above is not the answer, place code breaks in the code and find out if your code executes to the breakpoint.
The code is under a button and everything is fine. The file is in the right place and all the code gets executed, but this code was written to use Office 2003 and it doesn't seem to work completely with Office 2007.

Like I said above, when the code executes, the WINWORD.exe process runs in Task Manager, but the actual document does not appear in the foreground.

I am just wondering if anyone knows how to fix the problem to allow the code to work with Office 2007.

Thanks
Jul 12 '08 #3
puppydogbuddy
1,923 Recognized Expert Top Contributor
try changing line 26 to:
appWord.Visible = True
Jul 12 '08 #4
mlevit
30 New Member
try changing line 26 to:
appWord.Visible = True
Thanks man, that worked. But now it's not actually filling in the values from access.

Any ideas?
Jul 12 '08 #5
puppydogbuddy
1,923 Recognized Expert Top Contributor
Thanks man, that worked. But now it's not actually filling in the values from access.

Any ideas?
Not sure what you mean......was it filling the document before you made the above change? or has it never worked??

try moving lines 26 and 27 (below) to between line 13 and line 14.

appWord.visible = True
doc.activate
Jul 13 '08 #6
mlevit
30 New Member
Not sure what you mean......was it filling the document before you made the above change? or has it never worked??

try moving lines 26 and 27 (below) to between line 13 and line 14.

appWord.visible = True
doc.activate
Well the document never appeared on the screen (but now does after i inserted appWord.visible = True), so I'm not sure if it ever filled the data from Access (but I don't think it did).

The Word document opens but the fields that I want filled in with data from Access do not get filled in. I'll try your suggestion when I get home from work.

Thanks
Jul 13 '08 #7
mlevit
30 New Member
Ok I've tried moving the lines as you recommended but nothing. The Word document opens but none of the fields that I have in the Word document get filled in.

Maybe you could try doing the tutorial yourself quickly and see if it works for you?
Jul 13 '08 #8
puppydogbuddy
1,923 Recognized Expert Top Contributor
Ok I've tried moving the lines as you recommended but nothing. The Word document opens but none of the fields that I have in the Word document get filled in.

Maybe you could try doing the tutorial yourself quickly and see if it works for you?
If you read the followup posts to the tutorial, there were several people that could not get it working. Here is the response from Susan Harkins, creator of the tutorial

1. Be sure to reference the Microsoft Office Object Library. Using the VB Editor, choose References from the Tools menu, check, the library, close the dialog, and return to the document and try again

2. I'm sorry for the confusion. Use the "bookmark" property to name the form fields. I think if you make that change, it'll work fine for you. Let me know.

see this link:
http://techrepublic.com.com/5208-133...sageID=2319675
Jul 13 '08 #9
mlevit
30 New Member
The bookmark property is the name of the Form Field in Office 2003, but I can't see that same property in Office 2007.

When I add the Form Fields to my Word document, I can set their Title, but I'm not sure if that is their name that I would use in .FormFields("du eDateTem").Resu lt = DateDueToClient .Value.

I know there is a comment on the tutorial: "Hi is the office 2007 version avaliable yet? If so where can i find it please? "

So I don't think I'm the only one having the problem with Office 2007.
Jul 13 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2979
by: Ronny Sigo | last post by:
Hello all, I am a newbie to access. I try to pass data from a form into a new Word document Below you see how far I got ... can anybody help ? Private Sub btnMaakbrief_Click() If lGoon = False Then ' Here I check some of the controls to see if they contain required data, if not a msgbox is displayed
4
15814
by: Otis Hunter | last post by:
I have been given an Access Database which contains a table that has an OLE object field that contains a Word document. That table contains hundreds of records. I would like to find out how I can write a VB script, to be executed either within Access or executed at the CMD prompt, which will loop through all the records and open the document...
2
4384
by: kelly.pearson | last post by:
I had some access 97 reports that I used to publish to MS Word that worked before we upgraded to Access 2K and Word 2K. Although there were some minor discrepancies, I was able to tweak the access reports and fix those problems. After the upgrade to Office 2K, when I publish the report to MS Word a ..rtf document is created instead of a...
5
2167
by: Niklas Uhlin | last post by:
Someone please explain why Session_Start fires multiple times / retains SessionID values between sessions, when you open an ASP.NET page from MS Word. For details of the problem, see below: 1. Create a new C# ASP.NET web application named "demo" and modify Session_Start in Global.asax.cs as follows: protected void Session_Start(Object...
7
6229
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the user and populated (with info from an Access database) at run-time, then saved as Word documents. The program I have coded works fine -- it does...
5
6502
by: ruomingxu via AccessMonster.com | last post by:
I am new in this area. I want to use values in a Access database and pass them to a word document. I tried this test code in a form of the Access database but it didn't work (temp.doc is a word doc already stored in C: drive): Dim oX As Object Set oX = CreateObject("C:\temp.doc") oX.editreplace "<<FirstName>>", "Richard", 0, 1, 0, 0, 0,...
6
10289
by: MayBoy | last post by:
Hi There I am trying to use the Goto method of the Word ActiveX object. I am trying to open a document and go to a named bookmark. If I use this code in VB it works, so I'm sure the approach is possible, I just can't get JavaScript to work with it. Here is the code I am using, the error I get from IE is Object Expected: Hope someone can...
8
6692
by: babyangel43 | last post by:
Hello, I have a query set up in Access. I run it monthly, changing "date of test". I would like this query to be merged with a Word document so that the cover letter is created in Word, the fields from Access are automatically filled into the Word document. The query could be anywhere from 0-5000 names, one cover letter per name. AND to this...
4
3345
by: no8do | last post by:
Hi there, I am brand new in access and VBA programming and I am asking for your help. One of the fields in my db is of the OLE object data-type. I' ve written a vb script that is executed on a button's click on my form for openning an embedded word document, on which I can write text. The text is saved on the field as soon as I close the word...
0
7659
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7882
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6244
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5481
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3618
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2079
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1194
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.