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"