Help: Displaying Pictures in a form

Nizar

Registered User.
Local time
Today, 10:36
Joined
Oct 21, 2007
Messages
41
Hello everyone,

To display images on a form (Access 2003) I used the same code of the Northwind database sample (Form Emplyees).
when changing the Picture's location it returns a bug in the code (Couldn' open ...the file), or the ErrorMessage Label should have the value: "File not Found"
here is the code: any help if highly appreciated.
#
Private Sub Form_Current()
Dim res As Boolean
Dim fName As String
Path = CurrentProject.Path
On Error Resume Next
ErrorMsg.Visible = False
If Not IsNull(Me![ProductPicture]) Then
res = IsRelative(Me![ProductPicture])
fName = Me![ImagePath]
If (res = True) Then
fName = Path & "\" & fName
End If
Debug.Print "fName: " & fName
Me![ImageFrame].Picture = fName
showImageFrame
Me.PaintPalette = Me![ImageFrame].ObjectPalette
If (Me![ImageFrame].Picture <> fName) Then
hideImageFrame
ErrorMsg.Caption = "File not Found"
ErrorMsg.Visible = True
End If
Else
hideImageFrame
ErrorMsg.Caption = "Click on Add/Edit to add the Product Picture"
ErrorMsg.Visible = True
End If

End Sub

Function IsRelative(fName As String) As Boolean
IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
End Function
#

Best Regards,
 
Personally, if want to use images in your application I would do it properly i.e. not the Microsoft's way. Why Microsoft would put images into the Current Project Path defies reason. When I started to incorporate images into an Access 97, I had the choose between OLE and DBPix. I have never regretted going for dbpix, we now have 16,000 images.

Having had my gripe with MS, I would be first tempted to evaluate the FullPath of the Image I don't use sub routines only modules.

Code:
Function GetImage()

Dim FullPath As String

    With CodeContextObject
        FullPath = GetImageDir & .[Image File]

        If Dir([FullPath]) <> Empty Then
            Debug.Print "ImageFile " & FullPath
        Else
            Debug.Print "No File Exists"
        End If
    End With

End Function

Code:
Private Function GetImageDir() As String

    GetImageDir = CurrentProject.Path

End Function

The point of this code is to check to see if the file exists. Sometimes when I see MS's code I give up the will to live, so forgive my impertinence but putting images in your application is a great idea so I happy to help you acheive your objective. Don't whatever you do embed as a blob.

Simon
 
Many Thanks for your help and especially your advices.
Your post was highly helpful i appreciate that, many thanks again :)
Best Regards,
 

Users who are viewing this thread

Back
Top Bottom