Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2002
    Posts
    31

    Unanswered: what's wrong with this code -- Word Table Object

    Hi,

    this code crashes on the first "objTable.Cell" statement.

    Grts,
    *************

    docSql = "select field,bookmark from _PCPD where type='Table'"
    Set docRecSet = db.OpenRecordset(docSql, dbOpenSnapshot)

    dbSql = "select b.tifreleasename,b.tifreleasedate from tblProjectRun a,tblTifRelease b where a.tifrelease_key=b.tifrelease_id and a.project_key= " & Pr_id
    Set dbRecSet = db.OpenRecordset(dbSql, dbOpenSnapshot)

    tblCount = dbRecSet.RecordCount

    If tblCount <> 0 Then
    objWord.activedocument.bookmarks(docRecSet.Fields( 1)).select
    Set objTable = objWord.activedocument.Tables.Add(Range:=objWord.S election.Range, NumRows:=tblCount, NumColumns:=2)

    Dim i As Integer
    i = 0

    While i < tblCount
    objTable.Cell(Row:=i, Column:=1).Range.Text = dbRecSet.Fields(0)
    objTable.Cell(Row:=i, Column:=2).Range.Text = dbRecSet.Fields(1)
    dbRecSet.MoveNext
    i = i + 1
    Wend

    End If

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I don't see you instantiating objWord anywhere, how do you have that declared?
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Excel collections start at 1 not 0 . Change the i = 0 to i = 1 before your loop.

    HTH
    Testimonial:
    pootle flump
    ur codings are working excelent.

Posting Permissions

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