4

How exactly does one go about:

  1. getting images/pictures into a SQL database
  2. viewing pictures from a SQL database using a MS Access form?

I currently use an ODBC link between the two databases with no problems at all, but I'm struggling to understand what I need to do to achieve what I'm trying to achieve.
I have already tried Google, but haven't yet come across the right information.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
IT_Tech
  • 61
  • 2
  • 3

1 Answers1

2

Getting pictures in and out of an SQL Server database:

You need the GetChunk and AppendChunk functions for that.
Here's a tutorial: How To Read and Write BLOBs Using GetChunk and AppendChunk.
This tutorial is a bit dated, but as far as I know this is still the best way to load/save pictures in a database from VBA.
Note that in SQL Server, you should use a varbinary(max) field (instead of the image suggested in the tutorial) to store the pictures.

Displaying the pictures in an MS Access form:

You can't display a picture directly from the database. You have to load it from the database (see above), store it in a temp folder and display it from there.

To get Windows' temp folder, use Environ("temp") or the GetTempPath API function.

To display the picture you can either set it as the background of the form:

Me.Picture = "c:\...\temp\picture.jpg"

...or use a image control:

Me.NameOfImageControl.Picture = "c:\...\temp\picture.jpg"
Community
  • 1
  • 1
Christian Specht
  • 35,843
  • 15
  • 128
  • 182