access and word' work together???

24sharon

Registered User.
Local time
Today, 02:32
Joined
Oct 5, 2004
Messages
147
I have an application on access that export the data to word.

I did a query and the data export to word

my code is:
Code:
Dim db, rst
Dim strSQL As String

Set db = CurrentDb
'÷éùåø åôúéçú ååøã, åäöâúå áöåøä îåñøú
    Dim objWord 'As Word.Application
    'Set word as an application and make it invisible
    Set objWord = CreateObject("Word.Application")
    objWord.Visible = False 'True is visible
        
    'ùí äîñîê
    objWord.Documents.Add ("C:\doc3.doc")

        strSQL = Me.strSQL
        Set rst = db.OpenRecordset(strSQL)
        rst.MoveFirst
        Dim strString As String
        strString = ""
        Do While Not rst.EOF
        'ID---------------------------------
         strString = strString & rst!nameID & vbTab & vbTab & "|"
        'name-------------------------------
         If Not IsNull(rst!fName) Then
          strString = strString & rst!fName & vbTab & vbTab & "|"
        End If
        'lName---------------------------------
         If Not IsNull(rst!lName) Then
            strString = strString & rst!lName & vbTab & vbTab & "|"
        End If
        rst.MoveNext
        strString = strString & vbCrLf
        Loop
        objWord.ActiveDocument.Bookmarks("aaa").Select
        objWord.Selection.Text = strString
         objWord.Visible = True
my question:

I want to export the data to a table in word.
I attach the file
(to work good put the file "doc3.doc" to "c:/")
how can I do it?
thanks :)
 

Attachments

  • db9.zip
    db9.zip
    15.4 KB · Views: 139
  • 123.JPG
    123.JPG
    11.8 KB · Views: 199
I've never done any automation between Access and Word (never had need to) but I thought I'd fix the following that I saw in your code:

24sharon said:
my code is:
Code:
Dim db, rst

Code:
Dim db As DAO.Database
Dim rst As DAO.Recordset
 
24sharon said:
I want to export the data to a table in word.

The easy way to merge your data in a word document is :

In your Dbase : open the query you use to export data from >
select the records that you want to export > go to tools > office links > publish it with MS Word and all selected data is inserted in a word document.
The word doc includes your exported data in a table form. ( See attached)

Please note that Access can only merge to .rtf files if done thru the above described method.
 

Attachments

  • names.JPG
    names.JPG
    28.6 KB · Views: 172
You will need a reference to DAO and Word with this code.

Code:
Private Sub ToWord_Click()
Dim db As DAO.database
Dim rst As DAO.Recordset
Dim strSQL As String
Dim objWord As Word.Application
Dim wdDoc As Word.Document
Dim wdTbl As Word.Table
Dim intRow As Integer

Set db = CurrentDb
    
'Set word as an application and make it invisible
Set objWord = CreateObject("Word.Application")
objWord.Visible = False 'True is visible
        
    'ùí äîñîê
Set wdDoc = objWord.Documents.Add("C:\doc3.doc")
strSQL = Me.strSQL
Set rst = db.OpenRecordset(strSQL)
rst.MoveLast
rst.MoveFirst
Set wdTbl = wdDoc.Tables.Add(Range:=Selection.Range, NumRows:=rst.RecordCount, NumColumns:=3, AutoFitBehavior:=wdAutoFitFixed)
intRow = 0
Do While Not rst.EOF
    intRow = intRow + 1
    wdTbl.Cell(intRow, 1).Range.InsertAfter rst!nameID
    wdTbl.Cell(intRow, 2).Range.InsertAfter rst!fName
    wdTbl.Cell(intRow, 3).Range.InsertAfter rst!lName
    rst.MoveNext
Loop
 objWord.Visible = True
End Sub

HTH

Peter
 
butiful!!!!!!!!

I did it and its work good


just I put the bookmark to put the table in its place.


and here the result....


thank all! :p


[SJ McAbney I didnt write

Dim db As DAO.Database
Dim rst As DAO.Recordset
because I MISSING REFERENCES]
 

Attachments

  • 123.JPG
    123.JPG
    21.1 KB · Views: 163

Users who are viewing this thread

Back
Top Bottom