You are on page 1of 1

Option Compare Database

Option Explicit

Private Sub cmdGetPhoto_Click()


Dim cdb As DAO.Database
Dim con As ADODB.Connection, rst As ADODB.Recordset, stm As ADODB.Stream

Set cdb = CurrentDb


Set con = New ADODB.Connection
con.Open Mid(cdb.TableDefs("dbo_Clients").Connect, 6)
Set rst = New ADODB.Recordset
rst.Open "SELECT Photo FROM Clients WHERE ClientID=1", con, adOpenStatic, adLockOptimistic
Set stm = New ADODB.Stream
stm.Type = adTypeBinary
stm.Open
stm.Write rst("Photo").Value ' write bytes to stream
stm.Position = 0
Me.Image0.PictureData = stm.Read ' load bytes into Image control on form

stm.Close
Set stm = Nothing
rst.Close
Set rst = Nothing
con.Close
Set con = Nothing
Set cdb = Nothing
End Sub

You might also like