Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Export String to Word

Posted on 2011-09-15
3
Medium Priority
?
202 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

604 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