473,698 Members | 1,883 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
10 9241
puppydogbuddy
1,923 Recognized Expert Top Contributor
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.
I don't have word 2007, but the problem seems to be lack of documentation for word 2007 at this period in time. I looked, but could not find any solid info. Let's see if we can get one form field working.

Try replacing line 15 with lines 15a and 15b, then tell me what happens.

With doc
15. .FormFields("fl dCustomerID").R esult = Me!CustomerID


With doc
15a. .Bookmarks.Add Range:=Selectio n.Range, Name:= "fldCustome rID"

15b. Me!CustomerID = bookmarks("fldC ustomerID").ran ge
Jul 14 '08 #11

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

Similar topics

1
2981
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
15845
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 object and save it to a Word document that I can access from Windows Explorer. An additional info...
2
4397
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 .doc document and it has many problems. i.e., lines don't show up, words are missing, sentences are...
5
2173
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 sender, EventArgs e) { Response.Write("Session_Start event fired at "+
7
6242
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 what I need it to do. But it has two problems: (1) it runs very slowly, and (2) it does not seem to...
5
6511
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, 0, 0, 1, 0, 0, 0 oX.Application.Visible = True Set oX = Nothing
6
10292
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 help! Any help would be much appreciated
8
6719
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 cover letter for each applicant, there has to be attached a two page document. How in the world can...
4
3357
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 document. For the record, the code that I use is the following: A.Class = "Word.Document" ' Set...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7716
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
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
3
1998
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.