Assigning picture on selection

Kyriakos

Registered User.
Local time
Today, 19:59
Joined
Feb 18, 2006
Messages
42
Hey to all. I have this form in which I need according to a user selection to assign a picture and display it on the same form. Is this possible? How do I do this? Or can I display the picture to another form or a report based on the first form?

Thanks in advance.
 
Got some code for this. I will put it up in a couple of hours when I get home and look in my archive!
 
This is it:

Place an Image Frame on your form and Name it ImageFrame. Also place a small unbound textbox on top of the above Image Frame named txtImageNote. Give it the default vale "No image specified"


Form Code:

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

Private Sub Form_Current()
'
On Error GoTo Err_Record
'
intPath = CustomerID.Value
CallDisplayImage
If strResult = "" Then
txtImageNote.Visible = False
Else
txtImageNote.Visible = True
End If
'

Exit_Record:
Exit Sub
'
Err_Record:
Select Case Err.Number
'
Case 94
ImageFrame.Visible = False
Resume Exit_Record
'
Case Else
MsgBox Err.Number & " " & Err.Description
Resume Exit_Record
End Select

End Sub

also..

Private Sub Form_AfterUpdate()
intPath = CustomerID.Value
CallDisplayImage
'
If strResult = "" Then
txtImageNote.Visible = False
Else
txtImageNote.Visible = True
End If
End Sub


Now: ...

Place the following code in a Module - called (say)
Image Module


Option Compare Database
Option Explicit

Public strPath As Variant
Public intPath As Integer
Public strResult As String


Public Function DisplayImage(ctlImageControl As Control, strImagepath As Variant) As String
'
On Error GoTo Err_DisplayImage
'
'PATH to DEFAULT FOLDER
'======================
strPath = "c:\temp\" & intPath & ".jpg"
'
strImagepath = strPath
strResult = ""
'
With ctlImageControl

.Visible = True
.Picture = strImagepath

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 = "No image specified"
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


EXPLANATION:

Store the pictures in the c:\temp directory as its a path that was easier to code rather than all that Documents and Settings/Username etc stuff. The pictures have to be a jpeg and name them the exactly same number as the record number for your client.

When the form and record opens, if (say) picture 99.jpg exists for record ID 99 it will be visible on the form. If not, then the little image note text box will show No Image Specified.

Hope it works - if not let me know as I did all this a while ago. If needed I can zip up the relevant parts but that will not be until tomorrow. Hopefully you can work out the code.

Have fun.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom