I searched on Google to find the best way to display images in Access without actually inserting the image into the database.
I found this article http://support.microsoft.com/kb/285820 'through this thread Is there a way to get ms-access to display images from external files , which details how to set image paths through folders / files , and works great for the "set" image. However, I want a different picture to be displayed when switching to another record.
Here is the code from the article:
Option Compare Database Option Explicit Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String On Error GoTo Err_DisplayImage Dim strResult As String Dim strDatabasePath As String Dim intSlashLocation As Integer With ctlImageControl If IsNull(strImagePath) Then .Visible = False strResult = "No image name specified." Else If InStr(1, strImagePath, "\") = 0 Then ' Path is relative strDatabasePath = CurrentProject.FullName intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath)) strDatabasePath = Left(strDatabasePath, intSlashLocation) strImagePath = strDatabasePath & strImagePath End If .Visible = True .Picture = strImagePath strResult = "Image found and displayed." End If End With Exit_DisplayImage: DisplayImage = strResult Exit Function Err_DisplayImage: Select Case Err.Number Case 2220 ' Can't find the picture. ctlImageControl.Visible = False strResult = "Can't find image in the specified name." Resume Exit_DisplayImage: Case Else ' Some other error. MsgBox Err.Number & " " & Err.Description strResult = "An error occurred displaying image." Resume Exit_DisplayImage: End Select End Function
I have a feeling that I need to put a line of code that says something like, show an image where Image.ID = "ID", but I canβt figure out where to put it without getting errors. Am I looking at something, or am I approaching it wrong? I just don't want to clutter up my database, from memory, with .bmp images, but I feel like I have to.
SOLVED: A much simpler solution, as Gord Thompson described in the comments below. From my own experience, using this method for .bmp images leaves the image distorted and contrasting. I tested the image for .jpg and it works great! I hope this helps others who have problems with similar problems, find this post helpful.
vba access-vba image ms-access ms-access-2010
Dylan
source share