Link to home
Start Free TrialLog in
Avatar of JMS1965
JMS1965Flag for United States of America

asked on

Can't Display Image File in Access Runtime on Some Windows 7 Systems

I have an Access 97 runtine application with about 800 users.  (I know it's ancient ... I am currently re-writing / updating it, but that will take a few more months.)

One feature allows users to link to pictures in the database. The data table doesn't store the actual picture object; it stores the path to the picture (stored on the user's hard drive). The UI form allows the user to view the picture(s) and print as well.

This works as desired for the majority of users, but a handful of users with Windows 7 machines can't use this feature. When they try to add a picture, they get an error that the application doesn't support the file format, even though they are working with the standard JPG, GIF, or BMP formats.

To be clear, this is only happening to a few Win7 users. Many other Win7 users have no issue with the picture feature. I have two Win7 machines here and it works great on both, which of course makes it difficult for me to troubleshoot an issue that I can't reproduce.

I had a similar issue with this same application a number of years ago with Windows XP ... most users had no problem but a few received the "doesn't support this format" error. I was able to resolve that by creating a quick exe patch that set the Windows graphics filters on their machines ... they would run that once and then all would be fine.  Running that exe patch on the Win 7 machines has not resolved the issue, and I haven't turned up any helpful research on graphics filters in Win 7.

I worked with one user that was experiencing this issue and I remotely accessed his PC and compared relevant registry keys to those in my Win7 machine and found no differences.

I'm including the code for the UI form here; the first sub is used to display the picture and the second sub allows the user to browse for a picture file and then stores the path to that picture in the table.  

I would appreciate any suggestions to resolve this - whether it involves changing the code or something else that the user needs to do.  

Thanks in advance for any advice!
Private Sub Form_Current()
    On Error Resume Next
    If IsNull(Me.PicPath) = False Then
        Me.imgPic.Picture = Me.PicPath
    Else
        Me.imgPic.Picture = ""
    End If    
    Me.Refresh
End Sub

Private Sub btnAdd_Click()
    Dim theFlags As Long
    Dim strFilter As String
    Dim strFile As String
    Dim strPath As String
    Dim resp As Variant
    Dim i As Integer
    Dim rs As Recordset
    Dim db As Database
    Dim bkmark As Variant
    
    If Me.Dirty = True Then Me.Dirty = False
    
    If IsNull(Me.PicPath) = False Then
        resp = DisplayMessage(138)  'ask if they want to replace existing pic or add another pic record
        
        If resp = vbCancel Then GoTo Exit_btnAdd_Click        'don't add a new pic
        'get path of current file
        strPath = Me.PicPath
        For i = 1 To Len(strPath)
            If Right(strPath, 1) = "\" Then    'file name has been removed, only path is left
                Exit For
            Else
                strPath = Left(strPath, Len(strPath) - 1)
            End If
        Next i
    Else
        strPath = "C:\"                 'default directory
    End If
    
'get path and file name for picture.
    theFlags = ahtOFN_FILEMUSTEXIST + ahtOFN_HIDEREADONLY _
        + ahtOFN_NODEREFERENCELINKS + ahtOFN_LONGNAMES
    strFilter = ahtAddFilterItem(strFilter, "Graphic Files", "*.bmp;*.jpg;*.tif;*.wmf")
    strFile = ahtCommonFileOpenSave(theFlags, InitialDir:=strPath, Filter:=strFilter, _
        DialogTitle:="Location and Name of Picture", OpenFile:=False)
        
    If strFile = "" Then GoTo Exit_btnAdd_Click       'user cancelled dialog
    
    'make sure there is a parent record
    With Forms!HorseNotes
        If IsNull(!NoteID) = True Then
            If .NewRecord = True And .Dirty = False Then
                !Note = "[picture(s) included]"
                .Dirty = False      'save new note
            End If
        End If
    End With
        
    If resp = vbNo Then                     'add selected pic to a new record
        Set db = CurrentDb
        Set rs = Me.RecordsetClone
        With rs
            .AddNew
            !NoteID = Me.Parent!NoteID
            !PicPath = strFile
            .Update
            bkmark = .LastModified
            Me.Bookmark = bkmark        'move to new record
        End With
    Else
        Me.PicPath = strFile
    End If
    
    Call Form_Current
    
Exit_btnAdd_Click:
On Error Resume Next
    If Not (rs Is Nothing) Then rs.Close: Set rs = Nothing
    If Not (db Is Nothing) Then db.Close: Set db = Nothing
Exit Sub
End Sub

Open in new window

Private Sub Form_Current()
    On Error Resume Next
    If IsNull(Me.PicPath) = False Then
        Me.imgPic.Picture = Me.PicPath
    Else
        Me.imgPic.Picture = ""
    End If    
    Me.Refresh
End Sub

Private Sub btnAdd_Click()
    Dim theFlags As Long
    Dim strFilter As String
    Dim strFile As String
    Dim strPath As String
    Dim resp As Variant
    Dim i As Integer
    Dim rs As Recordset
    Dim db As Database
    Dim bkmark As Variant
    
    If Me.Dirty = True Then Me.Dirty = False
    
    If IsNull(Me.PicPath) = False Then
        resp = DisplayMessage(138)  'ask if they want to replace existing pic or add another pic record
        
        If resp = vbCancel Then GoTo Exit_btnAdd_Click        'don't add a new pic
        'get path of current file
        strPath = Me.PicPath
        For i = 1 To Len(strPath)
            If Right(strPath, 1) = "\" Then    'file name has been removed, only path is left
                Exit For
            Else
                strPath = Left(strPath, Len(strPath) - 1)
            End If
        Next i
    Else
        strPath = "C:\"                 'default directory
    End If
    
'get path and file name for picture.
    theFlags = ahtOFN_FILEMUSTEXIST + ahtOFN_HIDEREADONLY _
        + ahtOFN_NODEREFERENCELINKS + ahtOFN_LONGNAMES
    strFilter = ahtAddFilterItem(strFilter, "Graphic Files", "*.bmp;*.jpg;*.tif;*.wmf")
    strFile = ahtCommonFileOpenSave(theFlags, InitialDir:=strPath, Filter:=strFilter, _
        DialogTitle:="Location and Name of Picture", OpenFile:=False)
        
    If strFile = "" Then GoTo Exit_btnAdd_Click       'user cancelled dialog
    
    'make sure there is a parent record
    With Forms!HorseNotes
        If IsNull(!NoteID) = True Then
            If .NewRecord = True And .Dirty = False Then
                !Note = "[picture(s) included]"
                .Dirty = False      'save new note
            End If
        End If
    End With
        
    If resp = vbNo Then                     'add selected pic to a new record
        Set db = CurrentDb
        Set rs = Me.RecordsetClone
        With rs
            .AddNew
            !NoteID = Me.Parent!NoteID
            !PicPath = strFile
            .Update
            bkmark = .LastModified
            Me.Bookmark = bkmark        'move to new record
        End With
    Else
        Me.PicPath = strFile
    End If
    
    Call Form_Current
    
Exit_btnAdd_Click:
On Error Resume Next
    If Not (rs Is Nothing) Then rs.Close: Set rs = Nothing
    If Not (db Is Nothing) Then db.Close: Set db = Nothing
Exit Sub
End Sub

Open in new window

SOLUTION
Avatar of puppydogbuddy
puppydogbuddy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JMS1965

ASKER

Hi puppydogbuddy -

Looks like you have provided great info here ... I'll look into this later today and get back to you.

Thank you!
Avatar of Jeffrey Coachman
Just some notes...

As a general rule, I don't "Call" the current event. (like you are doing in your button click code)
I let it trigger on its own.
If you need this "Image code", then put it in its own sub and Call it from the current event.

This is because the current event can also contain other code that you may not want to run, if you only need to display an image.

Then in your Button _Click code I would call this new sub, (not the Current Event)

Something like this:

Private Sub DisplayImage()
    On Error Resume Next
    If IsNull(Me.PicPath) = False Then
        Me.imgPic.Picture = Me.PicPath
    Else
        Me.imgPic.Picture = ""
    End If    
    Me.Refresh
End sub


Private Sub Form_Current()
    'Some other code
    Call DisplayImage
    'Some other code
End Sub

Private Sub btnAdd_Click()
    Dim theFlags As Long
    Dim strFilter As String
    Dim strFile As String
    Dim strPath As String
    Dim resp As Variant
    Dim i As Integer
    Dim rs As Recordset
    Dim db As Database
    Dim bkmark As Variant
   
    If Me.Dirty = True Then Me.Dirty = False
   
    If IsNull(Me.PicPath) = False Then
        resp = DisplayMessage(138)  'ask if they want to replace existing pic or add another pic record
       
        If resp = vbCancel Then GoTo Exit_btnAdd_Click        'don't add a new pic
        'get path of current file
        strPath = Me.PicPath
        For i = 1 To Len(strPath)
            If Right(strPath, 1) = "\" Then    'file name has been removed, only path is left
                Exit For
            Else
                strPath = Left(strPath, Len(strPath) - 1)
            End If
        Next i
    Else
        strPath = "C:\"                 'default directory
    End If
   
'get path and file name for picture.
    theFlags = ahtOFN_FILEMUSTEXIST + ahtOFN_HIDEREADONLY _
        + ahtOFN_NODEREFERENCELINKS + ahtOFN_LONGNAMES
    strFilter = ahtAddFilterItem(strFilter, "Graphic Files", "*.bmp;*.jpg;*.tif;*.wmf")
    strFile = ahtCommonFileOpenSave(theFlags, InitialDir:=strPath, Filter:=strFilter, _
        DialogTitle:="Location and Name of Picture", OpenFile:=False)
       
    If strFile = "" Then GoTo Exit_btnAdd_Click       'user cancelled dialog
   
    'make sure there is a parent record
    With Forms!HorseNotes
        If IsNull(!NoteID) = True Then
            If .NewRecord = True And .Dirty = False Then
                !Note = "[picture(s) included]"
                .Dirty = False      'save new note
            End If
        End If
    End With
       
    If resp = vbNo Then                     'add selected pic to a new record
        Set db = CurrentDb
        Set rs = Me.RecordsetClone
        With rs
            .AddNew
            !NoteID = Me.Parent!NoteID
            !PicPath = strFile
            .Update
            bkmark = .LastModified
            Me.Bookmark = bkmark        'move to new record
        End With
    Else
        Me.PicPath = strFile
    End If
   
    Call DisplayImage
   
Exit_btnAdd_Click:
On Error Resume Next
    If Not (rs Is Nothing) Then rs.Close: Set rs = Nothing
    If Not (db Is Nothing) Then db.Close: Set db = Nothing
Exit Sub
End Sub
Avatar of JMS1965

ASKER

Boaq2000 -

Makes sense ... thanks for the tip! I'll make the recommended change.
Avatar of JMS1965

ASKER

puppydogbuddy -

Thanks again for the info. I have read the material / links you provided and it sure seems to be related to the issue some of my customers are having.

However, I'm a bit confused with the "Microsoft-speak" in the KB articles.  Just to clarify ... is the security patch causing the problem, or is it intended to resolve the problem?

If it is causing the problem, are they then saying that users have to manually edit their registry keys (thus creating a security hole) in order to use graphic files in Office programs? Yikes!

Sorry to bug you, but I just want to make sure I understand this before making my customers (who are very basic PC-users, not experts at all) jump through hoops so we can test this.

Thanks!
Avatar of puppydogbuddy
puppydogbuddy

Microsoft's patch disabled the graphics filters to alleviate a threat to Windows OS security (malicious code could be delivered behind an image).  Thus the patch created the problem you are having.

Yes, changing the registry keys would have to be done on each machine having the problem.  However, there are scripts that will automate the changes to the registry keys.  Try googling on "VB code to change the windows registry keys".
Avatar of JMS1965

ASKER

Sorry for the delay in updating this. I have had a hard time reaching any customers who have this issue in order to try to resolve it using the information you provided.  I'll keep trying and will post an update in the next few days.

Thanks!
Avatar of JMS1965

ASKER

Hello -

I have an update on this issue, which unfortunately is not resolved. I've connected with two customers who are experiencing the problem, and it seems the MS Security Patch referenced above is not the cause. Both of them had the problem before December, when the patch was released.

Does any one have any other suggestions?

Thanks!
Not sure.

There are quite a few questions here on "issues" with Win 7
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
see the link below for Microsoft's coded function to display images.  You should compare and test your code against the code provided by Microsoft and see if works.

http://support.microsoft.com/kb/285820
Avatar of JMS1965

ASKER

Hi puppydogbuddy -

I reviewed the KB article you referenced. Although I don't use a separate function as is shown in the article, I am using the same assignment method to display the image:

ControlName.Picture = FilePathFileName

Thanks anyway ...
Avatar of JMS1965

ASKER

Thanks for trying to help -- I so appreciate your efforts. Unfortunately this is unresolved; I will try to re-frame a new question. This issue is making me crazy!