Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 04-26-2019, 02:49 AM   #1
aman
Newly Registered User
 
Join Date: Oct 2008
Posts: 1,250
Thanks: 54
Thanked 3 Times in 2 Posts
aman is an unknown quantity at this point
Bookmark on word document

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.

aman is offline   Reply With Quote
Old 04-26-2019, 03:16 AM   #2
Gasman
Enthusiastic Amateur
 
Gasman's Avatar
 
Join Date: Sep 2011
Location: Swansea, South Wales,UK
Posts: 4,563
Thanks: 442
Thanked 847 Times in 818 Posts
Gasman is a jewel in the rough Gasman is a jewel in the rough Gasman is a jewel in the rough
Re: Bookmark on word document

Not played with them myself, but the syntax here apparently worked for the O/P

https://www.access-programmers.co.uk...d.php?t=304811
__________________
Access novice. Sometimes trying to give something back.
Access 2007

Please, please use code tag # when posting code snippets

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Gasman is offline   Reply With Quote
Old 04-26-2019, 07:32 AM   #3
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 33,399
Thanks: 13
Thanked 4,125 Times in 4,057 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: Bookmark on word document

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

__________________
Paul
Microsoft Access MVP 2007-2019

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is offline   Reply With Quote
Old 04-26-2019, 10:23 AM   #4
Cronk
Newly Registered User
 
Join Date: Jul 2013
Posts: 2,165
Thanks: 3
Thanked 472 Times in 465 Posts
Cronk will become famous soon enough Cronk will become famous soon enough
Re: Bookmark on word document

@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.

Cronk is offline   Reply With Quote
The Following User Says Thank You to Cronk For This Useful Post:
aman (04-29-2019)
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access VBA Code to insert Word Building Block in Word Document AngC Modules & VBA 2 10-31-2017 02:15 PM
Insert a word document in another word document cherosoullis Word 5 08-17-2011 12:24 AM
WINWORD.EXE not ends in word 2007 when Embedding word document in OLE UNBOUND CONTROL jambai Forms 0 04-21-2010 03:18 PM
Bookmark in a Text Box in Word johncallaghan Visual Basic 0 12-22-2008 12:57 PM
Access/Word/Bookmark Mike375 General 2 09-25-2008 12:03 AM




All times are GMT -8. The time now is 03:30 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World