Solved

Export String to Word

Posted on 2011-09-15
3
191 Views
Last Modified: 2012-05-12
Dear Experts.

From Access I to be able to export data in a string into a word document.

The String is below, what it does is create “blocks” of 25 email addresses (with a semi colon separating each).  I would like these blocks to be pasted into a word document separate by a line break i.e.

Emails 1-25

Emails 26 -50
Etc etc

Can anybody help?
 
Dim rst As Recordset
    Dim BccList As String, x As Integer
    Set rst = CurrentDb.OpenRecordset("AfricanMembersLive")
    Do While Not rst.EOF
    BccList = ""
    x = 1
   Do Until rst.EOF Or x >= 25
     BccList = BccList & rst!email & "; "
    x = x + 1
    rst.MoveNext
   Loop

Open in new window

0
Comment
Question by:correlate
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
Simon Ball earned 500 total points
ID: 36542291
Check out these two articles i found:

http://www.databaseadvisors.com/newsletters/newsletter072002/0207wordautomationlpt1.asp

http://www.databaseadvisors.com/newsletters/newsletter072002/0207wordautomationpt2.asp

Cribbed their word automation into a mock up of code.


 
Private Sub Command0_Click()

'Dim strpath As String

'strpath = "c:\temp.doc" ' enter your document name here or use

'Set doc = objWord.Documents.Open(strpath)


'or
Dim objWord As Object
Dim doc As Object
Set objWord = CreateObject(“Word.Application”)

Set doc = objWord.Documents.Open(“C:\Path\To\file.doc”)
' this is the bookmark in word to start the insert from
doc.Bookmarks(“OrderDate”).Select

Dim rst As Recordset
Dim BccList As String, x As Integer
    
    Set rst = CurrentDb.OpenRecordset("AfricanMembersLive")
    Do While Not rst.EOF
        BccList = ""
        x = 1
        Do Until rst.EOF Or x >= 25
            BccList = BccList & rst!email & "; "
            x = x + 1
            rst.MoveNext
        Loop
    objWord.Selection.TypeText BccList
'
    objWord.Selection.TypeText vbcrlf ' carriage return and line feed

    Loop

objWord.Close

Set objWord = Nothing

End Sub

Open in new window

0
 

Author Closing Comment

by:correlate
ID: 36718306
Hi Sudonim,

Thank you very much for this, & apologies for the delay in assigning points etc - thought I had done that

Works a treat
0
 
LVL 15

Expert Comment

by:Simon Ball
ID: 36813939
Lovely!

this is what i got in my email...

Microsoft Access Database: 298,192 total
1,808 more points to become a Wizard!

One good answer to go!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now