Solved

Export String to Word

Posted on 2011-09-15
3
197 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

730 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