Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002

    Unanswered: 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?


    ** 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
    End With

    objWord.activedocument.SaveAs newfilename
    Set objWord = Nothing

    Exit Sub

    MsgBox (Err.Description)
    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 ductCreation_template.doc"
    newfilename = "L:\RPC\PRODUCT_DEVELOPMENT\Products\ProductDb\Pro ductCreation_RunXXX.doc"

    Call ReportToWord(filename, newfilename)
    End Sub

  2. #2
    Join Date
    Feb 2004
    Chicago, IL
    Check your SQL. This error is usually do to a typo in the name of a field.

  3. #3
    Join Date
    Apr 2004
    outside the rim
    As DCKunkle suggests, it is probably the SQL. A quick and dirty test of SQL is to create a blank query, go into the SQL view and paste the SQL. When you run the query, the error message will be more specific.
    have fun!

    Todd S.
    click to email

    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET

    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  4. #4
    Join Date
    Oct 2002
    Thx. It was indeed an SQL-error.

    That leaves me with my real problem to tackle.

    As I have a query returning more rows with some recurring and some unique data like :

    Project - User - Format

    ProjectX John PDF
    ProjectX John Word
    ProjectX Marc PDF

    As i don't know in advance how many users or formats there will be returned, i only declared one bookmark (placed in a table), unfortunately it only fills in the first user/format.

    As long as i had only 1 row returned, it works really generic and i could use for more of my documents.

    Any help appreciated.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts