Using Access 97 to organise jpg files

  • Thread starter Thread starter Ingleby kernaghan
  • Start date Start date
I

Ingleby kernaghan

I want to use Access 97 to organise my photographs. How
can get a form to display the photograph?
 
Simplest approach is to use a Text field in your table to store the location
of the picture on your drive. In the form where you record this data, use
the AfterUpdate event of the text box and the Current event of the form to
load the picture into an Image control.

This example assumes you have:
- a Text field named "ImageFilename",
- an Image control named "imgPic"
- a label named "lblNoImage" to display if there is no picture.

Save the two functions below into a module.

In the AfterUpdate event procedure of the ImageFilename text box:
Private Sub ImageFilename_AfterUpdate()
Call LoadTheImage(Me.ImageFilename)
End Sub

In the Current event of the form:
Private Sub Form_Current()
Call LoadTheImage(Me.ImageFilename)
End Sub

------------code starts-----------------
Public Function LoadTheImage(varFile As Variant) As Boolean
'Purpose: Show/hide the picture, loading from file.
Dim bShow As Boolean

With Me.[imgPic]
If FileExists(varFile) Then
bShow = True
If .Picture = varFile Then
'do nothing
Else
.Picture = varFile
End If
End If
If .Visible <> bShow Then
.Visible = bShow
Me.lblNoImage.Visible = Not bShow
End If
End With
End Function

Public Function FileExists(varFullPath As Variant) As Boolean
On Error Resume Next
If Len(varFullPath) > 0& Then
FileExists = (Len(Dir$(varFullPath)) > 0&)
End If
End Function
------------code ends-----------------

You could use a Hyperlink field if you prefer, but you will then need to
parse the file name using HyperlinkPart(). For an introduction to Hyperlink
fields, see:
http://allenbrowne.com/casu-09.html
 
Previous answer is correct if we are talking about jpgs. Note ,however, that function fileexists
Public Function FileExists(varFullPath As Variant) As Boolea
On Error Resume Nex
If Len(varFullPath) > 0& The
FileExists = (Len(Dir$(varFullPath)) > 0&
End I
End Functio
may return incorrect results if file has system or hidden attributes ..
 
Back
Top