
Accessing an OLE Object via Web UI
Problem: How do I extract a "Word" OLE object from an
MS Access'97 database record and save to a WORD document
file for a user "browsing" into a web site to see the
document!
I inherited an MSAccess database to track test cases
and steps to execute test cases. The "steps" were written
in WORD and saved in an Access record OLE field. This
works quite well using Access forms to view and activate
WORD to do the editing. But, when I want to do online
reports, the WORD document is not accessable to most of
the data access controls that I've found. What I'd like
to do is use ADO or RDO or even DAO to open the table,
get records, and in particular get the WORD object saved
into a new file and redirect the page to point to the
newly saved document.
My first attempt was using ADO on ASP pages but could
not get the OLE Object into a word object. Then I tried
to just get it to work with VB 6.0 with code similar
to what follows:
Function GetSteps(sTestId) As Boolean
Dim obj as Object
Dim wdObj as WORD.Document
Dim sql as String
Dim db as Database
Dim rs as RecordSet
' GetSteps = False is assumed
' do stuff to open db (DAO Attempt shown)
On Error Goto GETERR
Set db = OpenDatabase("TestCasesDb.mdb")
sql = "SELECT [Test ID], [Is Document], [Test Procedure] " & _
"FROM tbl_TestCases WHERE [Test ID]='" & sTestId & "'"
Set rs = db.OpenRecordset(sql)
If rs![Is Document] Then
Set obj = rs![Test Procedure]
' FAILS ON NEXT LINE
Set wdObj.Document = obj
End If
GetSteps = True
Exit Function
GETERR:
Debug.Print Err.Description, Err.Number
End Function
What happens is a "Type Mismatch" even if I try to access
the field directly into wdObj.
My current kludge is to use an OLE control on a form,
use the old Data Access control and bind the OLE control
to the data access control. Setup the data access control
to point to my database and query for the test case I want
and then do:
Set wdObj = OLE1.object
OLE1.DoVerb vbOLEOpen
OLE1.DoVerb vbOLEUIActivate
wdObj.Application.Visible = False
wdObj.SaveAs sPath & sName ' path and name set prior
wdObj.Close False
Set wdObj = Nothing
Works great in a standard app! But need this online. So
I wrapped an ActiveX control to Shell out the app. Again, works
fine standalone but when running from the web I get:
Permission to use object denied
which is error 419
Then I tried setting write permission to the directory
where the files were going, "Write" access via web to
that same directory an still get the permission failure.
HELP.... There has to be a clean way to do this!
Any pointer to sample code, either on the MSDN library CDs (like
search does any good), or on the web, would be greatly
appreciated.
Thanks
Franc
_______ ______________________________________________________
/ Franc Woods
/ Network Peripheral Solutions Division
____ ___ / Hewlett-Packard, MS:5659
/ / / / Roseville, CA
__/ __/ _____/ /\~/\ 916/785-5065
___________ __/ ______ooO_{>v<}_Ooo_____________________________
``` U '''