[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

10/24/2009 at 07:02AM PDT, ID: 24840412 | Points: 500
[x]
Attachment Details

Retrieve File Extension for Embedded OLE Object

Asked by ADezii in Visual Basic Programming, VB Database Programming, Access Coding/Macros

Tags: OLE Object File Extension

I have a Table consisting of an OLE Object Field that contains Embedded Objects of varying Types (*.jpg, *.doc, *.rtf, etc...). I need to extract the Binary contents of these Fields into a Unique File for easy reference. This process I can easily accomplish via the Properties and Methods on an ADODB Stream Object, as long as the File Extension concurrently exists in the Table with the OLE Object. I wish this process to exist independently of the File Extension, namely: How can I extract the File Extension only from the contents of an OLE Object Field? I've posted my code below and it works flawlessly, but again, the File Extension co-exists along with the OLE Object. I thank you in advance for your help in this matter.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
Dim strSQL As String
Dim rstBLOB As ADODB.Recordset
Dim mstream As ADODB.Stream
Dim strFullPath As String
Const conTEMP_FOLDER As String = "C:\TEMP\"
 
'Return a 'Unique, Single Record via the Primary Key ([InvID])
strSQL = "SELECT tblInventoryPics.* FROM tblInventoryPics"
strSQL = strSQL & " WHERE tblInventoryPics.InvID=" & Me![InvID]
  
'Open an ADO Recordset
Set rstBLOB = New ADODB.Recordset
rstBLOB.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
 
If rstBLOB.RecordCount = 0 Then Exit Sub
rstBLOB.MoveFirst
 
'Create a Stream Object to contain the Binary Data from the OLE Object Field,
'(adTypeBinary), then Open it
Set mstream = New ADODB.Stream
mstream.Type = adTypeBinary
mstream.Open
 
'Write the contents of the OLE Object Field to the Stream
mstream.Write rstBLOB.Fields("oPicture").Value
 
'Save the Stream to a Unique Filename, represented by a combination of the Date,
'Time, and a File Extension as stored in the Table long with the OLE Object.
mstream.SaveToFile conTEMP_FOLDER & Format(Now(), "mmddyyyy_hhnnss.") & _
                   rstBLOB.Fields("sFileExtension").Value, adSaveCreateOverWrite
 
'Close the BLOB and set to Nothing before it devours you (LOL)!
rstBLOB.Close
Set rstBLOB = Nothing
[+][-]10/24/09 07:45 AM, ID: 25652434

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/24/09 12:25 PM, ID: 25653845

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/24/09 08:06 PM, ID: 25655360

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/25/09 10:24 AM, ID: 25657356

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/25/09 09:58 PM, ID: 25659727

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10/30/09 03:28 PM, ID: 25707190

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/30/09 04:21 PM, ID: 25707410

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/22/09 02:10 PM, ID: 25883930

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74 - Hierarchy / EE_QW_3_20080625