ACC2002: Unexpected Behavior with Images on Employees Form (282384)



The information in this article applies to:

  • Microsoft Access 2002

This article was previously published under Q282384
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SYMPTOMS

When you manipulate images in the Employees form in the sample database Northwind.mdb, the images may appear brown and patchy, or they may reappear after being deleted.

RESOLUTION

The following sample code corrects both of the issues concerning images in the Employees form described in the "Symptoms" section.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To insert new code behind the Employees form, follow these steps:
  1. Open the sample database Northwind.mdb.
  2. Press ALT+F11 to open the Microsoft Visual Basic Editor.
  3. In the Project Explorer window, open the Microsoft Access Class Objects folder, and then double-click Form_Employees.
  4. In the code module, delete all existing code.
  5. Type or paste the following Visual Basic for Applications code:
    Option Compare Database
    Option Explicit
    
    Private Sub AddPicture_Click()
        ' Use the Office File Open dialog to get a file name to use
        ' as an employee picture.
        getFileName
    End Sub
    
    Private Sub RemovePicture_Click()
        ' Clear the file name for the employee record and display the
        ' errormsg label.
        Me![ImagePath] = ""
        UpdateImage
    End Sub
    
    Private Sub Form_AfterUpdate()
        ' Requery the ReportsTo combo box after a record has been changed.
        Me!ReportsTo.Requery
    End Sub
    
    Private Sub Form_Current()
        UpdateImage
    End Sub
    
    Sub getFileName()
        ' Displays the Office File Open dialog to choose a file name
        ' for the current employee record.  If the user selects a file
        ' display it in the image control.
        With Application.FileDialog(msoFileDialogFilePicker)
            .Title = "Select Employee Picture"
            .Filters.Add "All Files", "*.*"
            .Filters.Add "JPEGs", "*.jpg"
            .Filters.Add "Bitmaps", "*.bmp"
            .FilterIndex = 3
            .AllowMultiSelect = False
            .InitialFileName = CurrentProject.path
            If (.Show <> 0) Then
                Me![ImagePath] = Trim(.SelectedItems.Item(1))
                UpdateImage
            End If
        End With
    End Sub
    
    Function IsRelative(fName As String) As Boolean
        ' Return false if the file name contains a drive or UNC path
        IsRelative = (InStr(1, fName, ":") = 0) And (InStr(1, fName, "\\") = 0)
    End Function
    
    Sub UpdateImage()
        ' Display the picture for the current employee record if the image
        ' exists.  If the file name no longer exists or the file name was blank
        ' for the current employee, set the errormsg label caption to the
        ' appropriate message.
        Dim stFileName As String
    
        On Error Resume Next
        
        If Not IsNull(Me!Photo) Then
            stFileName = Me![ImagePath]
            If IsRelative(stFileName) Then
                stFileName = CurrentProject.path & "\" & stFileName
            End If
            
            Me![ImageFrame].Picture = stFileName
    
            If (Me![ImageFrame].Picture <> stFileName) Then
                Me![ImageFrame].Visible = False
                errormsg.Caption = "Picture not found"
                errormsg.Visible = True
            Else
                Me.PaintPalette = Me![ImageFrame].ObjectPalette
                errormsg.Visible = False
                Me![ImageFrame].Visible = True
            End If
        Else
            Me![ImageFrame].Visible = False
            errormsg.Caption = "Click Add/Change to add picture"
            errormsg.Visible = True
        End If
    End Sub
    					
  6. Quit the Visual Basic Editor and return to Microsoft Access. Test the form; the pictures should appear as expected.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

MORE INFORMATION

Steps to Reproduce Behavior

The first issue is that when you delete images in the Employees form, the image comes back when the record is saved. To reproduce this behavior, follow these steps:
  1. Open the sample database Northwind.mdb.
  2. Open the Employees form.
  3. Click Remove.
  4. On the Records menu, click Save Record.
Note that the image comes back, overlaid with the label.

The second issue is that palette manipulation does not occur when the image is updated. To reproduce this behavior, follow these steps:
  1. Set the color resolution under your display properties to 256 colors.
  2. Open the sample database Northwind.mdb.
  3. Open the Employees form.
  4. Navigate to the second record and click Add/Delete.
  5. Navigate to C:\Program Files\Microsoft Office\Office 10\Samples and select EMPID1.BMP. Note the poor color definition and patchy appearance of the image.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbbug KB282384