Bill Benson
bensonforums at gmail.com
Wed Nov 19 16:55:43 CST 2014
I was toying with the idea of creating a backend document management
database in MS Access. I was going to zip files and then import them into
the database table with ADO, using the ADO Stream object.
All the below code (which doesnt have the ZIPPING code - but that will be
added later) runs fine, and there is no error message. But when I check the
contents of the OLE Object field in the record, it is empty.
Which makes me quite unhappy, I wrote a lot of code and built a userform
dialog assuming this was going to work.
I think these streams used to be able to be stored in dbMemo type fields -
I am sure I had at one time been successful.
I don't think I could even try to think of how to do this with ADO using an
Attachments field instead, since I dount ADO knows what that is. In any
case, I tried making the field type attachment in Access and the code did
not run - runtime error at the assignment of the .Value.
I don't think I can get this to run using inlineSQL ("Insert into blah
blah" because I don't know what I would use for the "Values ( )" clause.
Has anyone succeeded where I am failing?
Public Sub Upload()
Dim stmFileStream As New ADODB.Stream
Dim RS As New ADODB.Recordset
Dim oConn As ADODB.Connection
Const strPath = "C:\Users\wbenson\Documents\Development\Document Database
Project\Doc1.docx"
Set oConn = MyConn 'Trust me, this connection works
With stmFileStream
.Open
.Type = adTypeBinary
.LoadFromFile strPath
End With
With RS
.ActiveConnection = oConn
.LockType = adLockOptimistic
.CursorType = adOpenDynamic
.Open "SELECT * FROM Revision Where 1 = 2"
.AddNew
.Fields("File").Value = stmFileStream.Read
.Fields("Path") = strPath
.Update
.Close
End With
stmFileStream.Close
Set stmFileStream = Nothing
Set RS = Nothing
End Sub