How can I store a Visio drawing in an Access database using VBA in access?

T

Thomas

I manually created a table in an Access database with a column of type
"OLE Object". I manually created a Visio drawing and copied it to the
clipboard. Then I pasted that drawing into the above database. Works
like a charm, I can use mailmerge to create a Word document with
embedded drawings.

How can I do the same thing programmatically? I got as far as using
VBA in Access to create the Visio drawing, but then how do I get the
Visio.Drawing object into the "OLE Object" column of the database?

When I run the code below it creates a
"Run-time error '-2147217887(80040e21)':
Multiple-step OLE DB operation generated errors. Check each OLE DB
status, if available. No work was done."

in the line
rs.Fields("diagram") = doc

Any help would be appreciated. I only have limited experience with VB
and next to nothing with OLE.

Thanks,

Thomas
P.S.: Here's the code:
Option Compare Database

Sub initvisio()

Dim va As Visio.Application
Dim doc As Visio.Document
Dim master As Visio.master
Dim stencil As Visio.Document
Dim var As Visio.shape

Set va = CreateObject("visio.application")
Set doc = va.Documents.Add("")
Set doc = va.ActiveDocument



Set stencil = va.Documents.Open("Basic Shapes.vss")

Set master = stencil.Masters.Item("Cross")
va.Windows(doc.Index).Activate

Set var = va.ActiveDocument.Pages(1).Drop(master, 1, 1)

Dim rs As ADODB.Recordset


Set rs = New ADODB.Recordset
rs.Open "select diagram from Table2", CurrentProject.Connection,
ADODB.adOpenKeyset, ADODB.adLockOptimistic

rs.Fields("diagram") = doc

rs.Update
rs.Close

va.Quit


End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top