hi everyone, i have successfully saved the image file to DB by this code:

Private Sub cmdSave_Click()
Dim picsm As ADODB.Stream
Set picsm = New ADODB.Stream
picsm.Type = adTypeBinary
picsm.LoadFromFile filepath
With rs
.Fields("Last") = txtLast.Text
.Fields("First") = txtFirst
.Fields("Pic") = picsm.Read
MsgBox "Successful"
End With
Set picsm = Nothing
End Sub

But anyone can help me retrieve this image from DB and load it into the IMAGE CONTROL on the form?

i have this code:

Private Sub cmdSearch_Click()
Dim photo As String
squery = "select * from tblpic where Last='" & txtLast.Text & "'"
photo = rs.Fields("pic")

Set cm = New ADODB.Command
With cm
.ActiveConnection = conn
.CommandText = squery
.CommandType = adCmdText
End With
Set rs = New ADODB.Recordset
With rs
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockPessimistic
.Open cm
End With
With Me
.txtLast = rs!Last
.txtFirst = rs!First
.imgPic.Picture = LoadPicture(App.Path & "\pic\" & photo)
End With
End Sub

here is the error:

"file/path access error."

how could i retrieve the picture in the Access DB,
i think a folder must be reserved for the location of the photo.

thanks for the response.

try the following sample code

Dim CN As New ADODB.Connection
Dim RS As ADODB.Recordset
Dim DataFile As Integer, Fl As Long, Chunks As Integer
Dim Fragment As Integer, Chunk() As Byte, i As Integer, FileName As String

Private Const ChunkSize As Integer = 16384
Private Const conChunkSize = 100

Private Sub Form_Load()
    CN.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Pubs;Data Source=Test"
    Dim strsql As String

    strsql = "SELECT * FROM pub_info where pub_id = '9999'"
    RS.Open strsql, CN, adOpenForwardOnly, adLockReadOnly
    Set RS = Nothing
    Set RS = New Recordset
End Sub

Private Sub ShowPic()
    DataFile = 1
    Open "pictemp" For Binary Access Write As DataFile
        Fl = RS!logo.ActualSize ' Length of data in file
        If Fl = 0 Then Close DataFile: Exit Sub
        Chunks = Fl \ ChunkSize
        Fragment = Fl Mod ChunkSize
        ReDim Chunk(Fragment)
        Chunk() = RS!logo.GetChunk(Fragment)
        Put DataFile, , Chunk()
        For i = 1 To Chunks
            ReDim Buffer(ChunkSize)
            Chunk() = RS!logo.GetChunk(ChunkSize)
            Put DataFile, , Chunk()
        Next i
    Close DataFile
    FileName = "pictemp"
    Picture1.Picture = LoadPicture(FileName)
End Sub
This article has been dead for over six months. Start a new discussion instead.