Solved

Export String to Word

Posted on 2011-09-15
3
198 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

688 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