how to insert table into a word document.

how to insert table into a word document.

Post by Clifford Sutto » Tue, 26 Feb 2002 21:54:48



Public Sub createwordattachment()

Dim x As Word.Document
Dim I, s As Integer
Dim lneprint As String
Dim space As String
Dim sep As Integer

For I = 1 To 100
space = space & " "
Next I
    Set x = New Word.Document
    With x.ActiveWindow.Selection
    .BoldRun

    .TypeText lneprint

     sep = Len(Client_No)
     lneprint = Client_No & Left(space, 50 - sep) & ShpNumber
    .TypeText lneprint & vbCrLf
     sep = Len(Client)
     lneprint = Client & Left(space, 50 - sep) & ShpClient
    .TypeText lneprint & vbCrLf
     sep = Len(Address1)
     lneprint = Address1 & Left(space, 50 - sep) & ShpAddress1
    .TypeText lneprint & vbCrLf
     lneprint = Address2 & Left(space, 50 - Val(Len(Address2))) &
ShpAddress2
    .TypeText lneprint & vbCrLf
     lneprint = City & ", " & Province & Left(space, 50 - Val((Len(City) +
Len(Province)))) & ShpCity & ", " & ShpProvince
    .TypeText lneprint & vbCrLf
     lneprint = Postal_Code & Left(space, 50 - Val(Len(Postal_Code))) &
ShpPostal_Code
    .TypeText lneprint & vbCrLf
    .TypeText vbCrLf
    .TypeText vbCrLf

    .BoldRun
     For s = 1 To rsOrder.RecordCount
    .TypeText rsOrder!Item & "  "
     Set rsDescription = dbmain1.OpenRecordset("select item,
description,descriptionfr,um,umfr from invent where item = '" &
Trim(rsOrder!Item) & "'", dbOpenSnapshot)
    If Len(rsDescription!Description) < 25 Then
     .TypeText rsDescription!Description & vbTab & vbTab & rsOrder!quantity
& vbTab & Format(rsOrder!price, "##0.00") & vbTab &
Format(Val(rsOrder!price) * Val(rsOrder!quantity), "####0.00") & vbCrLf
   Else
    .TypeText rsDescription!Description & vbTab & rsOrder!quantity & vbTab &
Format(rsOrder!price, "##0.00") & vbTab & Format(Val(rsOrder!price) *
Val(rsOrder!quantity), "####0.00") & vbCrLf
    End If

    rsOrder.MoveNext
    Next s
    End With
    With x
    .SaveAs "c:\transfer\text"
    .Close
    End With
    Set x = Nothing

End Sub

 
 
 

1. Insert word document into table

Hi does anyone have any ideas about how to do this?
I have some code that I have been testing with but
it fails when I try to add the document to the
recordset, ANY help would be greatly appreciated.
Best regards // Greger Hagstr?m

Code follows:
Private Sub Command1_Click()
'---------INITIATE---------------------------------------------------
Dim Cmd As ADODB.Command
Dim Rs As ADODB.Recordset
Dim Con As ADODB.Connection
Dim Doc As Word.Document
'Dim Doc As Object

Set Cmd = New ADODB.Command
Set Rs = New ADODB.Recordset
Set Con = New ADODB.Connection
Set Doc = New Word.Document

'--------OPEN---------------------------------------------------
'Con.Provider = "Microsoft.Jet.OLEDB.4.0"
Con.Provider = "sqloledb"
Con.ConnectionString = "server=trainsql;Initial
Catalog=tmpCMDB_Extract;uid=sa;pwd=2l82go"
'Con.DefaultDatabase = "tmpCMDB_Extract"
Con.Open
'Con.Open "C:\Documents and Settings\qragrha\My Documents\Copy of
OLE-Object.mdb", "admin", ""

Set Doc = Word.Documents.Open("othello.doc")
'--------MAIN--------------------------------
'Rs.Open " SELECT tbl_Doc.Doc, tbl_Doc.Name FROM tbl_Doc ", Con,
adOpenKeyset, adLockOptimistic
Rs.Open " SELECT * FROM D_Documents ", Con, adOpenKeyset,
adLockOptimistic
'Debug.Print Rs.Fields("DOC").Value
'(auto)D_ID, C_ID, D_Name, D_Family, D_OLE
On Error Resume Next
Rs.AddNew
    Rs!C_ID = "1"
    Rs!D_name = "Testing docs"
    Rs!d_family = "Information"
    Rs!D_OLE = Doc
Rs.Update

Rs.Close
Rs.Open " SELECT tbl_Doc.Doc, tbl_Doc.Name FROM tbl_Doc ", Con,
adOpenKeyset, adLockOptimistic
While Not (Rs.EOF)
    With Rs.Fields
        Debug.Print .Item("Doc")
        Set Doc = .Item("Doc").GetChunk(5000000)
    End With
    Rs.MoveNext
Wend
Doc.SaveAs "c:\mittDokument.doc"
Doc.Save
Rs.Close

'--------CLEAN----------------------------------------------------
Set Cmd = Nothing
Set Rs = Nothing
Set Con = Nothing

End Sub

2. I'd like to connect M.S. Visual Foxpro to Infomix. What drivers do I need.

3. Filemaker record to word document and word document list

4. HELP DESK II SUPPORT ANALYST,Milwaukee,WI

5. Inserting a Word Document into Text field

6. US-CA-MEMBER OF TECHNICAL STAFF-DATA WAREHOUSE

7. Inserting Word Document into Image field

8. jBase on RedHat Linx 6.0

9. Can we insert a Word Document ??

10. Error inserting Word Document in image field

11. Insert Word document into a image field

12. Insert Word document into OLE Object field from C++

13. Insert Word Document in Access Ole field ?