Click to See Complete Forum and Search --> : Extracting image in databases using DAO 3.5 (Access DB)
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)
smalig
May 8th, 2000, 10:09 PM
Hi, try my code at
http://vbcity.com/vbcode/en/click.asp?id=71
Woohoo, gee thanks, i needed that to get smile on my face. Thanks a lot, i'll try it out...
PGrimshaw
Dec 11th, 2000, 08:04 AM
Could I have a copy of this code? The link is sending my to a Russion website.
Paul.
smalig
Dec 11th, 2000, 08:21 AM
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:
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
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.