Insert word document into table

Insert word document into table

Post by qrag.. » Fri, 25 Aug 2000 04:00:00



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

 
 
 

Insert word document into table

Post by Mujahi » Fri, 25 Aug 2000 04:00:00


Have a look at this article in the MSDN

HOWTO: Sample Functions Demonstrating GetChunk and AppendChunk
ID: Q194975

It has a BAS module with BLOBToFile and FileToBLOB reusable functions and a
good explanation.

--
Mujahid Wazir
IQura Technologies Pvt. Ltd


Quote:> 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


 
 
 

1. how to insert table into a word document.

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

2. (Story)

3. Filemaker record to word document and word document list

4. MS-SQL rollback lasts for HOURS, Table inaccessable in meantime

5. Inserting Word Document into Image field

6. Median

7. inserting field values into a word document

8. Insert OLE object (Word document) into Access DB

9. Insert Word document into a image field

10. Automatic inserting of data in a word document ?

11. Inserting a related link to a Microsoft Word document

12. Problems with Word Documents inserted into Filemaker?