Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

imbedding Word File

Status
Not open for further replies.

Shift838

IS-IT--Management
Jan 27, 2003
987
US
Is it possible to imbed/store a word file in an access database? if so how and where can I see some examples?
 
You can store a link to a file(s) or an address to it's location and use that to open it.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top