Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2008
    Posts
    50

    Unanswered: recordset reference

    OK, here's an easy one for you
    Really, I know I've done this before, but I'm having a brain freeze...

    I'm trying to fill in bookmarks in a set of word documents. There are several recordsets and (obviously) many fieldnames so I have the values in a table called tblSettlementDocFields. Here is my code. The problem is that mystr is a string, so it's putting the literal value into my document (e.g. myrs('PolicyNumber')) instead of the value (i.e. the actual policy number).
    What type should mystr be?
    Many thanks,
    Joanne


    'rsDoc is a recordset of the Doc IDs, there are 25 docs
    Do While Not rsDoc.EOF
    'get rs of bookmarks and fields for this doc
    Set rsFields = mydb.OpenRecordset("select * from tblSettlementDocFields where fkDoc=" & rsDoc!ID & ";")
    'open doc
    wrdApp.Documents.Open myPath & rsDoc!DocName
    wrdApp.Visible = True
    Do Until rsFields.EOF
    Dim mystr As String
    mystr = rsFields!RecordsetName & "('" & rsFields!FieldName & "')"
    ActiveDocument.Bookmarks(rsFields!BookmarkName).Ra nge.Text = mystr
    rsFields.MoveNext
    Loop
    'save doc
    saveDoc = savePath & myrs!CaseNumber & "\" & rsDoc!DocName
    'on error, create folder for case
    On Error GoTo err1
    ActiveDocument.SaveAs saveDoc
    'close this document, no save
    ActiveDocument.Close No
    rsDoc.MoveNext
    Loop
    'done, close word
    wrdApp.Quit

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    mystr is fine, I think. Try using

    mystr = rsFields!RecordsetName & "('" & rsFields!FieldName.Value & "')"

    to do what you want.

    HTH,
    Sam

  3. #3
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    If the problem is that MyStr is returning text, then convert it with something like CDbl(MyStr).
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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