You can embedd them if you want. The better way like the Captain said is to stare a link to them. This keeps the database from bloating. I know you can actually embedd them if you want but unfortunately do not have the code. I am sure it is out there.
There is a lot of code to embedd, retrieve, edit, and re-insert the file.
That is why most will store the path to the file and simply open the file using the retrieved link.
Andy Baldwin
"Testing is the most overlooked programming language on the books!
I was looking to do this the other day. Found this code that uses ADO stream. Need to have an ADO reference in the project (ADO 2.5+ I believe). Combined with Dev Ashish's apiShellExecute code, you can load files to an OLE/BLOB field, detach them and then launch them with the proper ap. Good luck.
Public Function WriteToFile(rs As ADODB.Recordset, str_full_path As String) As Boolean
On Error GoTo Er
Dim fds As ADODB.Stream
WriteToFile = False
Set fds = New ADODB.Stream
fds.Type = adTypeBinary
fds.Open
'get data from field in current record
fds.Write rs!OLE_FIELD
fds.SaveToFile str_full_path, adSaveCreateOverWrite
WriteToFile = True
Done:
fds.Close
Set fds = Nothing
Exit Function
Er:
Select Case Err.Number
Case 3004: ' file is in use!
MsgBox "File is either already in use or it's file permissions are incorrect. Check the path or the file may be in use.", vbExclamation, "WriteToFile()"
Case Else:
'Unexpected, fail with message box
MsgBox "Error # " & Err.Number & "--" & Error, vbCritical, "WriteToFile()"
End Select
Resume Done
End Function
Public Function ReadFromFile(rs As ADODB.Recordset, str_full_path As String)
On Error GoTo Er
Dim fds As ADODB.Stream
ReadFromFile = False
Set fds = New ADODB.Stream
'Make it a binary type
fds.Type = adTypeBinary
'Open the stream
fds.Open
'
'*** Read the binary file into the stream buffer ***
'
fds.LoadFromFile str_full_path
' save binary data into Field of current record
rs!OLE_FIELD = fds.Read
rs.Update
ReadFromFile = True
Done:
fds.Close
Set fds = Nothing
Exit Function
Er:
Select Case Err.Number
Case 55
Close
Resume
Case 3002
MsgBox "Could not read file (" & str_full_path & ") , check the path or the file may be in use."
Case Else:
'Unexpected, fail with message box
MsgBox "Error # " & Err.Number & "--" & Error, vbCritical, "ReadFromFile()"
End Select
Resume Done
End Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.