469,631 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,631 developers. It's quick & easy.

Problem with filling in Bookmarks in Word

Hi all,

I'm experiencing some problems when filling in bookmarks in word.

With my first query (single row returned), no problem at all. Yet, with
my new query (which now return 2 rows), i get some error message. -->
"Too few parameters, expected 1).

I'm having a table which describes what bookmark fits to what field. I
query this table to generically fill out my word-document.

I pasted my code below, you can still see my first query (in comment).
It's the 'dbSql' query.

Probable i'll have to put in some intelligence to figure out it is a
more-than-1-row-returned query?

Grts,
Kevin

************************************
** CODE**
************************************
Option Compare Database
Option Explicit

Sub ReportToWord(filename, newfilename)
On Error GoTo ReportToWord_err

Dim objWord As Object
Set objWord = Nothing
Set objWord = CreateObject("Word.application")
objWord.Documents.Open filename
objWord.Visible = False

Dim db As Database
Dim docRecSet As Recordset
Dim docSql As String
Dim dbRecSet As Recordset
Dim dbSql As String

Dim Pr_id As Integer

Pr_id = [Forms]![_MsWord]![cmbProject]

Set db = CurrentDb

docSql = "select * from _PCPD"
Set docRecSet = db.OpenRecordset(docSql, dbOpenSnapshot)

dbSql = "select tblProject.nickname,tblProject.internalreleasedate
,tblProjectRun.ProjectRunType from tblProject,tblProjectRun where
tblProject.Project_id=tblProjectRun.project_key and
tblProject.Project_ID= " & Pr_id
'dbSql = "select tblProject.nickname,tblProject.internalreleasedate
from tblProject where tblProject.Project_ID= " & Pr_id
Set dbRecSet = db.OpenRecordset(dbSql, dbOpenSnapshot)

With docRecSet
Do Until .EOF
With objWord.activedocument.bookmarks
objWord.activedocument.bookmarks(docRecSet.Fields( 1)).select
objWord.selection.Text = dbRecSet.Fields(docRecSet.Fields(0))
End With
..MoveNext
Loop
..Close
End With

objWord.activedocument.SaveAs newfilename
objWord.activedocument.Close
objWord.Quit
Set objWord = Nothing

ReportToWord_exit:
Exit Sub

ReportToWord_err:
MsgBox (Err.Description)
objWord.activedocument.Close
objWord.Quit
Set objWord = Nothing
GoTo ReportToWord_exit
End Sub

Private Sub cmdCreatePCPD_Click()
Dim filename As String
Dim newfilename As String

filename = "L:\RPC\PRODUCT_DEVELOPMENT\Products\ProductDb\Pro d
uctCreation_template.doc"
newfilename = "L:\RPC\PRODUCT_DEVELOPMENT\Products\ProductDb\Pro d
uctCreation_RunXXX.doc"

Call ReportToWord(filename, newfilename)
End Sub
********************************

Nov 13 '05 #1
1 2594
umm... did you try moving through the recordset a record at a time and
sending the records that way? Of course, there *is* code in the
Developer's Handbook that shoves data from Access to Word using
Bookmarks. You might want to have a read. Be warned, though, you have
to have a pretty good grip on Access and VB before most of the book
will mean anything. Otherwise, it's a $50 paperweight. That said, if
you _do_ have basic knowledge, it's an awesome resource.

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Raj Singh | last post: by
1 post views Thread by electrixnow | last post: by
3 posts views Thread by andreas | last post: by
2 posts views Thread by Mike Fellows | last post: by
2 posts views Thread by Alan T | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.