Here is an example that works for me. A few words of explanation first -
the image files are jpg, They are stored in a folder called "labels" and my
control names may be different from yours. If you want user to type "foot"
and see image of foot, then picture must be called "foot".
First- in the afterupdate event of your textbox:
Private Sub txtName_AfterUpdate()
Me!txtImageName = "C:\Bulk Wine Program\Labels\" & txtName & ".jpg"
CallDisplayImage 'calls subroutine
End Sub
then on the same form, put this sub:
Private Sub CallDisplayImage()
If Not IsNull(Me!txtImageName) Then
Me!txtImageNote = DisplayImage(Me!ImageFrame, Me!txtImageName) '
calls function "DisplayImage"
Dim mymatch As Integer
Dim strFirst As String
Dim strSec As String
strFirst = Me!txtImageName
strSec = "\"
mymatch = InStrRev(strFirst, strSec, -1, 1)
mymatch = Len(strFirst) - mymatch
Me!txtName = right(txtImageName, mymatch)
Me!txtImageNote.Visible = True
End If
End Sub
This is the function that I have in a module:
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 for 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
HTH
Damon