Link to home
Start Free TrialLog in
Avatar of imajdn
imajdn

asked on

How can I add a bitmap to an Access database using VB5 or VBA?

I am currently having a problem getting a bitmap image into Access without having to edit the data, click the field, selecting "Insert Object..." then creating an object from file. I have a VB5 application that currently writes the bitmap to the database field but it gets stored as "Long binary data" instead of "Bitmap Image". I am using Crystal Reports 6 to do my reporting and it insists on bitmap images. The "Long binary data" format is no use. Is there anyway in VB5 or VBA to take a bitmap image and save it into the OLE object field retaining the "Bitmap Image" format, not the "Long binary data" format? Thanks in advance.
Avatar of tcurtin
tcurtin

Hi imajdn,
Have you tried writing the bitmap image to the database 'as object'. Where is the file coming from?
Avatar of imajdn

ASKER

tcurtin,
   when you say writing the image as an object, how do you propose to do this in VB5?

The file is stored on my hard disk or on a server. I load it into my VB5 app using LoadPicture to set the picture property of an image control. The image control is connected to a data control which in turn is connected to the database field. When I load the image in it is automatically saved to the database.

Cheers.

ASKER CERTIFIED SOLUTION
Avatar of Belz
Belz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of imajdn

ASKER

Hi Belz,
   you have lost me. If this can be done then please show me how as I'm not sure I know
what to do. I am currently working on something else at the moment and have had to shelve this for the moment. If you can show me the code to do this then I'll give you the points but I don't have the time to explore copying/pasting to/from the clipboard to the database. I know the syntax is something like object.Copy and object.Paste but I don't know how to combine this with an Access 97 database. Thanks in advance.

I'm not 100% sure how your creating your bitmap in VB5.  Is it written to the harddrive, displayed on the screen, or in memory as an object.


Avatar of imajdn

ASKER

Hi Belz,
   the bitmaps are either files on my hard disk or I load them into an image control using LoadPicture to set the picture property.

Cheers.
Here's what I just setup and ran and it works

FORM:
2 command buttons - Copy BMP and a Reset
2 Text Boxes - Test1 and Test2
2 Unbound Objects - Test1 and Test2
1 option set with 2 options - one for direct set of BMP and the second to use the clipboard.

TABLE:
1 Table - 2 Fields - Test1 (Ole Object), Test 2(Ole Object)
Manually paste a BMP into Test1.

CODE:
Option Compare Database
Option Explicit

Private Sub cmdCopy_BMP_Click()
       
    Select Case optMethod
    Case 1 ' Direct Setting of BMP
        Me.obdTest2 = Me.obdTest1
        DoEvents
    Case 2 ' Copy / Paste of BMP
        Me.obdTest1.SetFocus
        DoCmd.RunCommand acCmdCopy
        Me.obdTest2.SetFocus
        DoCmd.RunCommand acCmdPaste
    End Select
    Me.Requery
   
End Sub

Private Sub cmdReset_Click()

     Me.obdTest2 = Null
     
End Sub

I forgot to tell you that you can also do the same thing with the text boxes instead of the unbound object frame.