ACC2002: Unexpected Behavior with Images on Employees Form (282384)
The information in this article applies to:
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:
- 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] = ""
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
- Quit the Visual Basic Editor and return to Microsoft Access.
Test the form; the pictures should appear as expected.
STATUSMicrosoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbbug KB282384 |
---|
|