Solved

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

Posted on 1998-09-30
8
451 Views
Last Modified: 2008-02-26
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.
0
Comment
Question by:imajdn
  • 4
  • 3
8 Comments
 
LVL 3

Expert Comment

by:tcurtin
Comment Utility
Hi imajdn,
Have you tried writing the bitmap image to the database 'as object'. Where is the file coming from?
0
 

Author Comment

by:imajdn
Comment Utility
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.

0
 
LVL 2

Accepted Solution

by:
Belz earned 200 total points
Comment Utility
Instead of setting the image directly into the table in the MDB, use the clip board.  Can you set the focus to the object in your VBA code then send the keys to copy it into the clipboard then set the focus to the table field and do a paste.  the clipboard will keep the native BMP formatting.
0
 

Author Comment

by:imajdn
Comment Utility
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.

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 2

Expert Comment

by:Belz
Comment Utility
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.


0
 

Author Comment

by:imajdn
Comment Utility
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.
0
 
LVL 2

Expert Comment

by:Belz
Comment Utility
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

0
 
LVL 2

Expert Comment

by:Belz
Comment Utility
I forgot to tell you that you can also do the same thing with the text boxes instead of the unbound object frame.
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now