This article provides an alternate method for displaying images associated with a record.
Let's say you have a Form
frmCoolCars
. Each record in your main Table tblCars
has an image of the car associated with that record. Rather than uploading your image to the DB, you can save that image to a common location. For example, C:\Users\twinnyfo\Documents\DB\Cars\Images\
. Create an additional text field in your table called CarImage
. In that field, eneter the pull path and filename of your image: C:\Users\twinnyfo\Documents\DB\Cars\Images\Ferarri .jpg
.Now, just add an image control to your form (
imgCar
). Set the .PictureType
Property to Linked, but make sure you do not include anything for the .Picture
property. This comes later.Now, in the OnCurrent Event of your Form, add the following code;
Expand|Select|Wrap|Line Numbers
- Private Sub Form_Current()
- On Error GoTo EH
- Me.imgCar.Picture = Me.CarImage
- Exit Sub
- EH:
- MsgBox "There was an error going to the current record!" & vbCrLf & vbCrLf & _
- "Error: " & Err.Number & vbCrLf & _
- "Description: " & Err.Description & vbCrLf & vbCrLf & _
- "Please contact your Database Administrator.", vbCritical, "WARNING!"
- Exit Sub
- End Sub
Keep in mind that you're probably gonna wanna double-check a few things, like making sure the image exists, before you set the image file. You can also add code in your form to browse for image files and save that location/filename, and there would even be possibilities for adding multiple images for one record. BUT, this article is just a quickie on the basics--just in case you ever wanted to do something like this, so all the bells and whistles have been removed.