Removing Form Icon (1 Viewer)

Access_Help

Registered User.
Local time
Today, 05:46
Joined
Feb 12, 2005
Messages
136
Please help me to remove the form default icon.
I don't want anything in replace of it.




A simple solution rather one that requires modules of code.

The links under this thread did not help.

Thanks in advance.
 

Attachments

  • icon.JPG
    icon.JPG
    8.5 KB · Views: 1,322

isladogs

MVP / VIP
Local time
Today, 12:46
Joined
Jan 14, 2017
Messages
18,186
I don't think it can be done without using module code ...but someone may prove me wrong
Here's how I do it.

Create a standard module and add this code

Code:
Option Compare Database
Option Explicit

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

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

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

NOTE: if using 64-bit the API declarations will need to be modified accordingly

Then in your form, add this code

Code:
Private Sub Form_Load()

    SetFormIcon Me.hWnd, "G:\MyFiles\Icons\1.ico" 'Replace with location of your icon file
    
End Sub

Hope that helps

BTW I found much the same code in one of the links below:
https://access-programmers.co.uk/forums/showpost.php?p=201741&postcount=6

EDIT:
You can also replace the Access application icon in the title bar with another of your choice.
This is done from Access Options...Current Database
 
Last edited:

vba_php

Forum Troll
Local time
Today, 07:46
Joined
Oct 6, 2019
Messages
2,884

isladogs

MVP / VIP
Local time
Today, 12:46
Joined
Jan 14, 2017
Messages
18,186
Posts crossed. I'd just made a similar point in an edit to my previous answer.
 

GinaWhipp

AWF VIP
Local time
Today, 08:46
Joined
Jun 21, 2011
Messages
5,901
Hmm, if you put your own Close button and remove the Control Box there will be no Form icon.
 

isladogs

MVP / VIP
Local time
Today, 12:46
Joined
Jan 14, 2017
Messages
18,186
Gina
I assume you meant a borderless form. I didn't suggest that as the OP wanted a different form icon rather than none.
 

GinaWhipp

AWF VIP
Local time
Today, 08:46
Joined
Jun 21, 2011
Messages
5,901
@Colin,

It is not a border-less Form. Go to any Form in Design View and set Control Box to No. You still have a border you just have no icon in the border. The down side is you also have no Close button so you have to add your own.
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 12:46
Joined
Jan 14, 2017
Messages
18,186
Gasman
Oops. I did misread post #1. Hence all that API code unnecessarily!

Gina
Thanks. Of course a borderless form has the same result ...and the same issue regarding making your own close button.
 

GinaWhipp

AWF VIP
Local time
Today, 08:46
Joined
Jun 21, 2011
Messages
5,901
Colin,

True, I just prefer to remove the icon and leave the border.
 

isladogs

MVP / VIP
Local time
Today, 12:46
Joined
Jan 14, 2017
Messages
18,186
Whereas I prefer the clean look of a borderless form, especially now I have code that allows me to move the form. Down to personal preference really.
 

Users who are viewing this thread

Top Bottom