Results 1 to 5 of 5

Thread: Extracting image in databases using DAO 3.5 (Access DB)

  1. #1
    Guest

    Unhappy

    I have been trying to store images in a database for sometime, i can do it directly from Access97 but i can't transfer these image to any control in VB.

    What i'm really doing is, i store the images for my toolbar buttons in a database so that the user can edit them and the changes will be kept. So what i need to know, is how do i extract and how do i update images directly from a ole-Object field in an Access 97 Database using DAO 3.5 (or 3.6, i got that one also, but i don't have the help file so i'm using 3.5)

  2. #2

  3. #3
    Guest

    Talking Woohoo thanks

    Woohoo, gee thanks, i needed that to get smile on my face. Thanks a lot, i'll try it out...

  4. #4
    Lively Member
    Join Date
    Nov 2000
    Posts
    88

    erm...

    Could I have a copy of this code? The link is sending my to a Russion website.

    Paul.
    Set MCP = NTServer + NTWorkstation

  5. #5
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Talking :)

    These messages you found was sent last year and I have now new great site but unfortunately only for russian speaking people Here is the code you request:

    Code:
    Dim dbTest As Database
    Dim rstAlbum As Recordset 
    Dim FileLen&, X%, lngOffset&, Chunks%, lngTotalSize& 
    Dim Arr() As Byte 
    Const ArrSize As Integer = 16384 
    
    Sub ReadPictureFromDb() 
    
    On Error Resume Next 
    
    Open "d:\picture.gif" For Binary Access Write As #1 
    lngTotalSize = rstAlbum!Picture.FieldSize 
    Chunks = lngTotalSize \ ArrSize 
    Fragment = lngTotalSize Mod ArrSize 
    
    ReDim Arr(ChunkSize) 
    Arr() = rstAlbum!Picture.GetChunk(lngOffset, ArrSize) 
    Put #1, , Arr() lngOffset = lngOffset + ArrSize 
    
    With rstAlbum 
    
    Do While lngOffset < lngTotalSize 
    Arr() = !Picture.GetChunk(lngOffset, ArrSize) 
    Put #1, , Arr() 
    lngOffset = lngOffset + ArrSize 
    Loop Close #1 
    .Close 
    
    End With 
    
    End Sub 
    
    Sub SavePictureToDb() 
    
    rstAlbum.AddNew
    
    Open "c:\picture.gif" For Binary Access Read As #1
    
    FileLen = LOF(1) Chunks = FileLen \ ArrSize Fragment = FileLen Mod ArrSize 
    
    ReDim Arr(Fragment) 
    
    With rstAlbum Get #1, , Arr() 
    
    !Picture.AppendChunk Arr() 
    ReDim Arr(ChunkSize) 
    For I = 1 To Chunks 
    Get DataFile, , Arr() 
    !Picture.AppendChunk Arr() 
    Next 
    Close #1 .Update
    
    End With 
    
    End Sub 
    
    Private Sub Form_Load() 
    
    Set dbTest = OpenDatabase("d:\db1.mdb", True) 
    Set rstAlbum = dbTest.OpenRecordset("select * from Album", dbOpenDynaset)
    
    SavePictureToDb 
    ReadPictureFromDb 
    
    Set rstAlbum = Nothing
    dbTest.Close 
    
    End Sub
    Have a nice day,
    Alexei

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width