By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,080 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,080 IT Pros & Developers. It's quick & easy.

Problem with filling in Bookmarks in Word

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.