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
Solved

Export String to Word

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

856 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