Bookmark on word document (1 Viewer)

aman

Registered User
Joined
Oct 16, 2008
Messages
1,250
Hi Guys,

I got bookmark added on word template where I want to display data from MS access query. The following code is written in Access but it doesn't populate any data in word document. I tried to run the query and it works fine but bk.range gives me null value in the following code:

Code:
 With CurrentDb.OpenRecordset("SELECT StandardDocs,strScore FROM qry_FormsCat_CallAudit_OverallScore WHERE (Section like 'Customer Outcome*') AND AuditID=" & Me.txtAuditID & "")
         Set bk = wd.Bookmarks("CustomerOutcome")
        'Set wt = wd.Tables.Add(wd.Parent.Selection.Range, 1, 3)
        Set wt = wd.Tables.Add(bk.Range, 1, 2)
        
        wt.Columns(1).Width = 465
        wt.Columns(2).Width = 50
   '     wt.Columns(3).Width = 150

        
      '  RowFormat wt.Range, False
        If Not .BOF = True And .EOF = True Then
        Do Until .EOF
        OutcomeScore = 0
            'CurSec = Split(.Fields(0), ".")
            Set wr = wt.Rows.Add
          '  wr.Cells(1).Range.Text = CurSec(1) & "." & CurSec(2)
            wr.Cells(1).Range.Text = .Fields(0)
            wr.Cells(2).Range.Text = .Fields(1)
        '    wr.Cells(3).Range.Text = .Fields(2)
       '     OutcomeScore = OutcomeScore + (.Fields(1)) * 10
            
            
            .MoveNext
        Loop
        wt.Rows(1).Delete
        End If
ANy help will be much appreciated.
 

pbaldy

Wino Moderator
Staff member
Joined
Aug 30, 2003
Messages
33,654
I ended up going a different way, but this was working for me in testing (Wrd being the Word document variable):

Wrd.ActiveDocument.Bookmarks("DriverName1").SELECT
Wrd.Selection.text = rs!First_Name & " " & rs!Last_Name
Wrd.ActiveDocument.Bookmarks("Date1").SELECT
Wrd.Selection.text = VBA.date
 

Cronk

Registered User
Joined
Jul 4, 2013
Messages
2,235
@aman, had you stepped through your code, you would have found that the loop is not executed. That is a reason for no data being inserted in your document.


Code:
(not .bof = true and .eof = true)
equates to false so the loop is skipped.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom