Adding a control to a form to add/replace a picture

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to add 2 controls to a form to allow the user to add/replace a
picture and another to delete the existing picture. I have looked at the
employee form in the Northwind sample database, which does the exact same
thing. Not being a VBA guru, I have not been able to make it work. Any help
you can provide would be greatly appreciated.

Ron
 
Ron,
Here's some code from one of my older applications.
The code is dealing with two controls: 1) An image
control named "PicturePath" and 2) a text box named
ImageID. If there's no picture name specified in the
bound control ImageID, or a specified name cannot
be found, then a default picture is used. The "jpg"
images are stored in a folder defined by a global
variable IPImages. (Note: some of this older code
is lacking in naming conventions. I.e., there are no
prefixes to denote what kind of "animal" you're
looking at, like ImageID ought to be something
like tbImageID and ImagePath ought to be something
like strImagePath.)

Bill

'================================================
Private Sub ImageID_AfterUpdate()
Call SetImagePath
End Sub
'================================================
Private Sub SetImagePath()

Dim ImagePath As String
Dim DefaultImage As String
Dim RegisteredImage As String

DefaultImage = IPImages & "\DefaultPic.jpg" 'We'll use the
default if no other specified
RegisteredImage = IPImages & "\" & [ImageID] & ".jpg" 'This won't
exist if ImageID is zero-length string

'See if we have picture other than the default picture.
If Dir(RegisteredImage) = "" Then
ImagePath = DefaultImage
If Len(ImageID) > 0 Then 'The ID is
specified, but there's no corresponding jpg file
MsgBox "There's no JPEG file corresponding to the name: " & ImageID
& " The image name is being reset."
ImageID = Null
End If
Else
ImagePath = RegisteredImage
End If

End Sub
'================================================
 
Back
Top