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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Access 2000 OLE Object Data type to readable text 1

Status
Not open for further replies.

MaxMcNaughton

Programmer
Sep 18, 2001
2
BR
I have a testing tool application that stores scripts, modules and class modules (programming code) not as text or memo type in a Access table but as OLE Object Data type described as 'Long binary data'. Ultimately i wish to take the code and store it in Excel or another Access Database but in text not in binary format.

I am to be the 'Librarian' of our teams classes, functions, procedures and i don't want to cut and paste and maintain from within the tool (it's basically VBA on testing qualuds), i want to be able to get at the binary data and automate the updating. Does anybody know of any code/or where i could look for a way to read the binary data.

Thanks for your attention,

Max
 
I figured out how to do this, so for your archives i'm sending it on. I have not included the windows API declarations and constants which you should be able to find.

Hope this helps someone else someday,

Public Function ImageToFile(ByVal strFileName As String, oField As ADODB.Field, strErrMsg As String) As Boolean
Dim strBuffer As String
Dim strFile As String
Dim bData() As Byte
ReDim bData(0 To FILE_BUFFER_SIZE - 1) As Byte
Dim lReturn As Long
Dim lByte As Long
Dim lByteCnt As Long
Dim lByteWritten As Long
Dim hFile As Long

On Error GoTo ErrorHandler
ImageToFile = False
hFile = 0
lByte = FILE_BUFFER_SIZE
lByteCnt = oField.ActualSize
lByte = 0
lByteWritten = 0
' Create File
hFile = CreateFile(strFileName, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0)
If (hFile = INVALID_HANDLE_VALUE) Then
strErrMsg = strErrMsg & vbCrLf & "Failed to create file " & strFileName
GoTo ErrorHandler
End If
' Write Data
Do While lByteWritten < lByteCnt
bData = oField.GetChunk(FILE_BUFFER_SIZE)
If (lByteCnt - lByteWritten) < FILE_BUFFER_SIZE Then
lReturn = WriteFile(hFile, bData(0), lByteCnt - lByteWritten, lByte, 0)
lByteWritten = lByteCnt
Else
lReturn = WriteFile(hFile, bData(0), FILE_BUFFER_SIZE, lByte, 0)
lByteWritten = lByteWritten + FILE_BUFFER_SIZE
End If
If lByteWritten >= lByteCnt Then
Exit Do
End If
Loop
' Close File
CloseHandle hFile
ImageToFile = True
Exit Function
ErrorHandler:
If hFile <> 0 Then
CloseHandle hFile
End If
If Err.Number <> 0 Then
strErrMsg = strErrMsg & vbCrLf & &quot;Reason:&quot; & vbCrLf & Err.Source & vbCrLf & Err.Description
End If
End Function

Max
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top