How to decode a blob datatype to string in VB / Access

Private Function Decode(ByRef rc As ADODB.Recordset) As String
Dim myStream As New ADODB.Stream
myStream.TYPE = adTypeBinary
myStream.Open
Call myStream.Write(rc.Fields(“theBlob”))
myStream.Position = 0

Dim sResults As String
sResults = “”

Do While Not myStream.EOS
sResults = sResults & Chr(AscB(myStream.Read(1)))
Loop

Decode= sResults & vbNewLine
End Function

This code had me scratching my head at first. The Stream.Write() method writes into the stream from the record field, not to some standard output like a file IO object would. Also be sure you’re referencing one of the newer versions of Microsoft ActiveX Data Objects X.X Library. I’m referencing 2.8 which works like a charm. The project I modified originally referenced 2.0 which didn’t even have a .Stream class in ADODB.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: