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\Prod
uctCreation_template.doc"
newfilename = "L:\RPC\PRODUCT_DEVELOPMENT\Products\ProductDb\Prod
uctCreation_RunXXX.doc"

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

.



Relevant Pages

  • Re: Setting Focus to Word
    ... I ran your exact code and only changed the document it was loading and it still won't maintain focus. ... Private Sub cmdWord_Click ... Dim oApp As Object ... Set objWord = CreateObject ...
    (microsoft.public.access.formscoding)
  • Re: Setting Focus to Word
    ... Are you saying that you still lose focus from the word doc when you run my ... Private Sub cmdWord_Click ... Dim oApp As Object ... Set objWord = CreateObject ...
    (microsoft.public.access.formscoding)
  • Printing in Word from Outlook custom forms
    ... Sue Moshers book on Outlook programming), I'm pretty new to this so I'm ... Dim m_blnWordPrintBackground ... Sub CmdPrint_Click ... Set objWord = createObject ...
    (microsoft.public.outlook.program_forms)
  • Re: Setting Focus to Word
    ... Private Sub cmdWord_Click ... Dim oApp As Object ... Set objWord = CreateObject ... 'Set Flag to let us know we opened Word ...
    (microsoft.public.access.formscoding)
  • Re: Setting Focus to Word
    ... Private Sub cmdWord_Click ... Dim oApp As Object ... Set objWord = CreateObject ...
    (microsoft.public.access.formscoding)