Microsoft KB Archive/304264

= ACC2000: How to Associate a Custom Icon with a Form =

Article ID: 304264

Article Last Modified on 10/11/2006

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q304264



Advanced: Requires expert coding, interoperability, and multiuser skills.

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



SUMMARY
In Microsoft Access, there is no built-in way to associate a custom icon for a form; however, this article demonstrates how to change a form's icon by using application programming interface (API) calls.



MORE INFORMATION
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.

Sample Code
To use API calls to set a custom icon for a form, follow these steps.

NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive an error message that there is a duplicate procedure name, remove or comment out the declaration statements in your code.   Create a module, and then type or paste the following code in the declarations section: Private Declare Function LoadImage Lib &quot;user32&quot; _ Alias &quot;LoadImageA&quot; _ (ByVal hInst As Long, _  ByVal lpsz As String, _   ByVal un1 As Long, _   ByVal n1 As Long, _   ByVal n2 As Long, _   ByVal un2 As Long) _ As Long Private Declare Function SendMessage Lib &quot;user32&quot; _ Alias &quot;SendMessageA&quot; _ (ByVal hWnd As Long, _  ByVal wMsg As Long, _   ByVal wParam As Long, _   LParam As Any) _ As Long Private Declare Function GetSystemMetrics Lib &quot;user32&quot; (ByVal nIndex As Long) As Long

Private Const WM_SETICON = &H80 Private Const IMAGE_ICON = 1 Private Const LR_LOADFROMFILE = &H10 Private Const SM_CXSMICON   As Long = 49 Private Const SM_CYSMICON   As Long = 50

Public Function SetFormIcon(hWnd As Long, strIconPath As String) As Boolean Dim lIcon As Long Dim lResult As Long Dim X As Long, Y As Long X = GetSystemMetrics(SM_CXSMICON) Y = GetSystemMetrics(SM_CYSMICON) lIcon = LoadImage(0, strIconPath, 1, X, Y, LR_LOADFROMFILE) lResult = SendMessage(hWnd, WM_SETICON, 0, ByVal lIcon) End Function   To set the icon, type the following code in the form's module (substitute the correct drive and path for your custom icon): Private Sub Form_Open(Cancel As Integer) SetFormIcon Me.hWnd, &quot;C:\MyIcon.ico&quot; End Sub 

