Question regarding VBA code displaying images in tabular form view

  • Thread starter Thread starter IloveGmail
  • Start date Start date
I

IloveGmail

Guest
Dear Forum,

I am currently creating a database for my artwork and images. Embedding is out of the question since I have about 10GB of pictures. Following the instructions here

http://support.microsoft.com/default.aspx?scid=kb;en-us;285820

I have been successful in creating tables and forms to display pictures with a link to the image file. However, I need to view many thumbnails at once. In the tabular form view however it displays the same picture in every record due to the modules and/or form code.

I am no whiz whith VB, but has anyone experienced similar problems and knows a solution? I would be most grateful.

For convenience I have attached the table, form, code and module structure.

yours

ILG




Table: tblImage
----------------------------
Field Name: ImageID
Data Type: AutoNumber
Indexed: Yes (No Duplicates)

Field Name: txtImageName
Data Type: Text

Table Properties: tblImage
--------------------------
PrimaryKey: ImageID





Form: frmImage
----------------------
Caption: Image Form
RecordSource: tblImage

Image Control
---------------------------------
Name: ImageFrame
Picture: "C:\Windows\Zapotec.bmp"

Text box
----------------------
Name: txtImageID
ControlSource: ImageID

Text box
---------------------------
Name: txtImageName
ControlSource: txtImageName

Text box
---------------------------
Name: txtImageNote
ControlSource: <Blank>



Form code:
Option Compare Database
Option Explicit

Private Sub Form_AfterUpdate()
CallDisplayImage
End Sub

Private Sub Form_Current()
CallDisplayImage
End Sub

Private Sub txtImageName_AfterUpdate()
CallDisplayImage
End Sub

Private Sub CallDisplayImage()
Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName)
End Sub




Module1:
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
 
Hello! Have you solved this problem?

Everything in your code is fine except the Image Control, simply change its properties:

Image Control
---------------------------------
Name: ImageFrame
Picture: (none)
Control source: txtImageName (the field from your table which contains the path and name of your image files)

1676461065863.png

Anyway, I attached the sample database file for you to try...
 

Attachments

Hello! Have you solved this problem?

Everything in your code is fine except the Image Control, simply change its properties:

Image Control
---------------------------------
Name: ImageFrame
Picture: (none)
Control source: txtImageName (the field from your table which contains the path and name of your image files)

View attachment 106458
Anyway, I attached the sample database file for you to try...
Hi. Welcome to AWF!

My guess is back in 2006, the Control Source property didn't exist yet.
 
Hi. Welcome to AWF!

My guess is back in 2006, the Control Source property didn't exist yet.
Yes, I guess so. That became my problem too few hours ago because the Microsoft's recommendation doesn't work but I've found my answer when someone in this forum had mentioned it. It helps a lot.
 
Hi. Welcome to AWF!

My guess is back in 2006, the Control Source property didn't exist yet.
Bound image control came out in 2007 I believe.
 

Users who are viewing this thread

Back
Top Bottom