Linking a picture to a form from network folder

randle

Registered User.
Local time
Today, 06:20
Joined
Jun 16, 2010
Messages
57
Hi


I have a form which shows individual records for users and I want to link photos for each record from a network folder rather than embedding them in the database as good practice suggests.


I've been using the database expample from http://www.databasedev.co.uk/image-form.html as a guide and have got it doing all I want other than actually displaying the picture in the picture control.


Form name: tblPerson
Picture path text field: txtImageName
Image Control: ImageFrame
Command button: cmdAddImage
Command button: cmdDeleteImage


The Event Procedure is assigned to the On Click event and looks like:
Code:
Private Sub cmdAddImage_Click()
On Error GoTo cmdAddImage_Err
Dim strFilter As String
Dim lngflags As Long
Dim varFileName As Variant
 
strFilter = "All Files (*.*)" & vbNullChar & "*.*" _
& vbNullChar & "All Files (*.*)" & vbNullChar & "*.*"
 
lngflags = tscFNPathMustExist Or tscFNFileMustExist _
Or tscFNHideReadOnly
 
varFileName = tsGetFileFromUser( _
fOpenFile:=True, _
strFilter:=strFilter, _
rlngflags:=lngflags, _
strDialogTitle:="Please choose a file...")
 
If IsNull(varFileName) Then
Else
Me![txtImageName] = varFileName
Forms![tblPerson].Form.Requery
End If
 
cmdAddImage_End:
On Error GoTo 0
Exit Sub
 
cmdAddImage_Err:
Beep
MsgBox Err.Description, , "Error: " & Err.Number _
& " in file"
 
Resume cmdAddImage_End
End Sub
 
Function setImagePath()
Dim strImagePath As String
On Error GoTo PictureNotAvailable
strImagePath = Me.txtImageName
Me.txtImageName.Locked = True
Me.txtImageName.Enabled = False
Me.ImageFrame.Picture = strImagePath
Exit Function
PictureNotAvailable:
strImagePath = "C:\Windows\Wind.bmp"
Me.ImageFrame.Picture = strImagePath
End Function
 
Private Sub cmdDeleteImage_Click()
Me.txtImageName.Enabled = True
Me.txtImageName.SetFocus
Me.txtImageName.Locked = False
Me.txtImageName.Text = ""
Me.txtImageName.SetFocus
Forms![tblPerson].Form.Requery
Me.txtImageName.Locked = True
Me.txtImageName.Enabled = False
End Sub
 
Private Sub txtImageName_AfterUpdate()
setImagePath
Forms![tblPerson].Form.Requery
End Sub


The image path is added to the picture path text field as expected but it's just the picture that isn't being displayed regardless of the requery at the end.


I'm a bit stuck here so would appreciate any help
 
Last edited:
If the name of the Image is the same of the RecordID all you need to do is to associate the image with the RecordID.

If the RecordID =1 then the Image should be 1.jpg or 1.bmp prior to Access 2007.

I define the Image Directory "globally" and the actual file in the underlying query supporting the form.

So the Forms OnCurrent I have GetPicture (existing records) or AfterUpdate on the EmployeeID GetPicture. This is a Function.

Simon
 
I've sorted this now thanks. I just had to change the Control source property of the Image frame to the txtImageName field and now shows as expected. Simples ;)
 

Users who are viewing this thread

Back
Top Bottom