Microsoft KB Archive/282384

= ACC2002: Unexpected Behavior with Images on Employees Form =

Article ID: 282384

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2002 Standard Edition

-



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 &quot;Symptoms&quot; 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:  Open the sample database Northwind.mdb. Press ALT+F11 to open the Microsoft Visual Basic Editor. In the Project Explorer window, open the Microsoft Access Class Objects folder, and then double-click Form_Employees. In the code module, delete all existing code.  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] = &quot;&quot; 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 = &quot;Select Employee Picture&quot; .Filters.Add &quot;All Files&quot;, &quot;*.*&quot; .Filters.Add &quot;JPEGs&quot;, &quot;*.jpg&quot; .Filters.Add &quot;Bitmaps&quot;, &quot;*.bmp&quot; .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, &quot;:&quot;) = 0) And (InStr(1, fName, &quot;\\&quot;) = 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 & &quot;\&quot; & stFileName End If       Me![ImageFrame].Picture = stFileName

If (Me![ImageFrame].Picture <> stFileName) Then Me![ImageFrame].Visible = False errormsg.Caption = &quot;Picture not found&quot; 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 = &quot;Click Add/Change to add picture&quot; errormsg.Visible = True End If End Sub  Quit the Visual Basic Editor and return to Microsoft Access. Test the form; the pictures should appear as expected.</li></ol>

<div class="status_section">

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

<div class="moreinformation_section">

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.

Additional query words: pra

Keywords: kbbug KB282384

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.