ðH geocities.com /Heartland/Pond/4805/Form1.htm geocities.com/Heartland/Pond/4805/Form1.htm .delayed x ½PÔJ ÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ Ð®ì äE OK text/html p0i äE ÿÿÿÿ b‰.H Sun, 20 Jan 2002 13:00:04 GMT ? Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98) en, * ¼PÔJ äE
How to Associate a Custom Icon with a Form |
The information in this article applies to:
Microsoft Access 2000
Microsoft Visual Basic for Applications
Advanced: Requires expert coding, interoperability, and
multiuser skills.
This article applies to a Microsoft Access database (.mdb) and a Microsoft
Access project (.adp).
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.
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 "user32" _
Alias "LoadImageA" _
(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 "user32" _
Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
LParam As Any) _
As Long
Private Declare Function GetSystemMetrics Lib "user32" (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, "C:\MyIcon.ico"
End Sub
For more information about declaration APIs, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type declare statement in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
Additional query words: custom icon form api