
Saving Graphic Image to Access Database?
Hi John,
Try This:
Look at this:
Dim pBag As PropertyBag
Dim pByteA() As Byte 'Array for raw data
Dim lRecCount As Long
Dim i As Integer
dbData.Recordset.MoveLast
lRecCount = dbData.Recordset.RecordCount
dbData.Recordset.MoveFirst
Select Case Index
Case 0 'Attach
For i = 1 To lRecCount
picToAttach.Picture = LoadPicture("I:\PUBLI\WINLOGOS\BMP16\" &
dbData.Recordset!File_Name & ".BMP")
'Create propertybag
Set pBag = New PropertyBag
'Write object
pBag.WriteProperty "MyPicture", picToAttach.Picture
'Fill array with binary data of pic
pByteA = pBag.Contents
'Assign raw data to OLE Object field of MDB
dbData.Recordset.Edit
dbData.Recordset.Fields("Embedded_Pic").Value = pByteA
dbData.Recordset.Update
dbData.Recordset.MoveNext
DoEvents
Next i
Case 1 'Test
For i = 1 To lRecCount
pByteA = dbData.Recordset.Fields("EMBEDDED_PIC").Value
Set pBag = New PropertyBag
pBag.Contents = pByteA
Set picToAttach = pBag.ReadProperty("MyPicture")
dbData.Recordset.MoveNext
DoEvents
Next i
Quote:
>Hi All,
>I have a problem saving a picture in a Picture Box to an Access Database.
>I made the access database field of type OLE OBJECT.
>I try to take a picture and save it to this field by writing:
> Table!Pic = PictureBox.Picture
>I have also tried a number of other ways as well but keep getting errors
>mostly complaining about data types.
>The odd thing is that I can accomplish this task easily by using a Data
>Object (such as DA0 Record Object) and Binding the Picture Box to the Field
>in the database. I don't want to Bind anything if I can help it.
>Any suggestions would be greatly appreciated.
>Thanks,
>John.