473,322 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

access to word interface using a document with bookmarks

Hi there,
I am having trouble getting all my records to be placed into my WORD document from my ACCESS form. I have a form with a subform displayed and a control button that executes a macro. The macro just says runcode MergeToWord and the following is my VBA code:

CODE:

Sub MergeToWord()
On Error GoTo MergeToWord_err

Dim objWord As Object
Set objWord = Nothing
Set objWord = CreateObject("Word.application")
objWord.Documents.Open "C:\Documents and Settings\messersmithm\My Documents\LOAR Creation\LOARtemp.doc"
objWord.Visible = True

With objWord.ActiveDocument.Bookmarks
.Item("Report_No").Range.Text = Forms![LOAR Log Form]![Report_Number]
.Item("Rev_No").Range.Text = Forms![LOAR Log Form]![Rev]
.Item("Rev_Date").Range.Text = Forms![LOAR Log Form]![Rev_Date]
.Item("Model_No").Range.Text = Forms![LOAR Log Form]![Model]
.Item("Serial_No").Range.Text = Forms![LOAR Log Form]![Serial_Number]
.Item("Sub_Rev").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Revision]
.Item("Sub_Date").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Change_Date]
.Item("Sub_Desc").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Change_Description]
.Item("Sub_By").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Submitted_By]
.Item("Dept_Code").Range.Text = Forms![LOAR Log Form].[LOAR Log Query Subform].Form![Department_Code]
End With

objWord.ActiveDocument.SaveAs "C:\Documents and Settings\messersmithm\My Documents\LOAR Creation\LOAR.doc"
objWord.ActiveDocument.Close
objWord.Quit
Set objWord = Nothing

MergeToWord_exit:
Exit Sub

MergeToWord_err:
MsgBox (Err.Description)
objWord.ActiveDocument.SaveAs "C:\Documents and Settings\messersmithm\My Documents\LOAR Creation\LOAR.doc"
objWord.ActiveDocument.Close
objWord.Quit
Set objWord = Nothing
GoTo MergeToWord_exit

End Sub

END CODE:

The data from the main form and the first record from the subform appear in the word document just fine but the additional records on the subform do not. I do not know how to tell it to loop until they are all placed in the document. I tried a Do Until .EOF but it did not work and messed everything up.

Thanks so much,
DeeDee
Jul 27 '07 #1
1 3027
Rabbit
12,516 Expert Mod 8TB
You need an outer loop outside of your With statements to loop through the records.
Aug 8 '07 #2

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

Similar topics

4
by: Jeff Harbin | last post by:
I've got an ACCESS 2000 application that I'm developing. One of the outputs of this app will be to generate a series of 'jobs' which corresponds to a record in the database. Each record will be...
4
by: Dadio | last post by:
Hello On my Access database form I have a command button which opens a Word mail merge document in which I have created a number of fields (Title, FirstName, LastName, Address1 etc.) I would...
6
by: Ryan Muller | last post by:
My company just upgraded from Access 97 to Access 2003 today and we are having some issues in a database that generates a Word document from information selected in a form. Here is the code we...
0
by: Raj Singh | last post by:
I am facing a problem with Visual C# 2003 and MS Word XP. I am using a customized template for Word and in that template I have defined some bookmarks. I am trying to create a Word document based...
1
by: Elizabeth Harmon | last post by:
Hi All I am attempting to open a Word App from a web page and so far everything works (After reconfig of dcomcnfg for Microsoft Word Document). I have one minor problem, i cannot get the...
5
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...
3
by: AccessThis | last post by:
Hi everyone, I’m fairly new to Access and VBA, but I have set up the following code to export all the records in my database to a word template (C:\Template.dot) with bookmarks (bkfield1,...
1
by: kirkus84 | last post by:
I am currently trying to do a multiple record mail merge through a query via a command button on a form. The query basically displays customers who have said yes to privacy. The user inputs a date...
2
by: Newbie23 | last post by:
Hi All (yet ANOTHER question) The reason for the merge is to create a Quote letter for the selected customer. It's working fine except for the contact address not showing. I have re-written the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.