Change icon next to form caption (1 Viewer)

systemx

Registered User.
Local time
Today, 19:27
Joined
Mar 28, 2006
Messages
107
Hi all,

A simple request but not sure if it can be done!

I would like to change the icon next to the form 'Caption' in the title bar to my own custom icon.

Does anyone know how I can access this property programattically (or at all?).

Regards,

Rob
 

boblarson

Smeghead
Local time
Today, 03:27
Joined
Jan 12, 2001
Messages
32,068
Yes, buy Access 2003 or Access 2007. If you have one of those, you can set an application icon in the startup properties and you can check the box that says to use the same icon for forms/reports.

I think there may be some API programming out there that can change the form's icons, but I haven't found one that worked for me.
 

systemx

Registered User.
Local time
Today, 19:27
Joined
Mar 28, 2006
Messages
107
Thanks mate. I am developing in Access 11.

I was hoping to access it programmatically to use differnet icons for seperate forms - depending on which 'area' of the DB the user is currently in.
 

Oldsoftboss

AWF VIP
Local time
Today, 22:27
Joined
Oct 28, 2001
Messages
2,504
From my code archive... you need to do 3 things

1.. create an icon!
2.. add the code below to a module
3.. add the SetFormIcon code to the load event of each form

Code to have Icon on a form...

'place this sub in each forms "Load" event
Private Sub Form_Load()

SetFormIcon Me.hWnd, Left(CurrentDb.Name, Len(CurrentDb.Name) - Len(Dir(CurrentDb.Name))) & “\myicon.ico"
‘if the icon file is stored in the same directory as the db
‘or
SetFormIcon Me.hWnd, "C:\Icons\Icon1.ico" 'Location of icon file

End Sub

'copy below code in a new public module
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

Dave
 

vbaDev

Registered User.
Local time
Today, 06:27
Joined
Feb 26, 2007
Messages
64
Hi. I tried this code, as well as some other similar methods, one of which provided by Microsoft.

Somehow it doesn't work for me. No error messages, but the icon doesn't change.

BTW, I like your statement of making the icon path "portable" so that one doesn't have to change path during deployment. I'll be sure to use that if I get the code to work.

If it helps, my main form (whose icon i am trying to change) opens and minimizes Access window, so it appears as standalone app (and that's why i want a custom icon). So the form is a "popup" (but not modal)

Does it matter what the file format of the icon is? I had it made from a bitmap and changed its extension to .ico.

Thanks!

P.S. I also tried it in a blank Access 2000 database with only 1 form and no bells/whistles (and without any "Hide Access" code). Still didn't work.
 
Last edited:

boblarson

Smeghead
Local time
Today, 03:27
Joined
Jan 12, 2001
Messages
32,068
I could never get the darn thing to work either, for some reason (probably user error, as is 99% of my problems), so I gave up and don't worry about it.
 

vbaDev

Registered User.
Local time
Today, 06:27
Joined
Feb 26, 2007
Messages
64
I could never get the darn thing to work either, for some reason (probably user error, as is 99% of my problems), so I gave up and don't worry about it.

Well, considering I tried MS code in its unchanged state and it didn't work either, I don't really think it's "user error" :)

Such a simple, obvious feature and they couldn't think of adding it until what, 2002? 2003? No wonder people are "surprised" by the housing market crash etc. :D

Maybe someone will point us in the right direction here (with Access form icons).
Thanks!
 

Oldsoftboss

AWF VIP
Local time
Today, 22:27
Joined
Oct 28, 2001
Messages
2,504
I add this to every DB I design, without fail.:confused:

Try the attachment. It has 2 forms, Form1 sets the Access window title and icon, as well as the form icon and caption. Form2 sets the form icon and title

HTH

Dave
 

Attachments

  • icon test.zip
    27.2 KB · Views: 3,632

vbaDev

Registered User.
Local time
Today, 06:27
Joined
Feb 26, 2007
Messages
64
Ok, thanks for providing those icons. They helped me to realize that it's not the code, it's my icon! Your icons work in my app (proper icons) and my bitmap with extension changed to ".ico" does not :)

I'll have to design a proper icon in Photoshop and save it as such.

Thanks for your help. It really looks slick when it works!
 

vbaDev

Registered User.
Local time
Today, 06:27
Joined
Feb 26, 2007
Messages
64
Sure enough, a proper icon designed in Photoshop works fine. I had to download a freeware Photoshop ICO plugin.
 

boblarson

Smeghead
Local time
Today, 03:27
Joined
Jan 12, 2001
Messages
32,068
 

vbaDev

Registered User.
Local time
Today, 06:27
Joined
Feb 26, 2007
Messages
64
That's cool.

But I already have Photoshop and used to working with it, removing the background, adding shadows, effects, etc., so for me it's easier to stick with it.

Thanks!
 

Maurina51

New member
Local time
Today, 03:27
Joined
Dec 31, 2008
Messages
1
For anyone reading this - I had a heck of a time until I realized the icon will not show up if you have ControlBox property set to no. It must be set to yes.
 

raphael99

Registered User.
Local time
Today, 03:27
Joined
Apr 6, 2015
Messages
126
How to work on 64 bit? Aanyone has the code?
 
Last edited:

mrrcomp

Registered User.
Local time
Today, 13:27
Joined
May 3, 2010
Messages
16
Hi

Does anyone have this working in Access 2016 64 Bit??? Tabbed Forms??

Regards

Meir:banghead:
 

jpdev

New member
Local time
Today, 03:27
Joined
Apr 1, 2019
Messages
1
The code provided by Oldsoftboss works BUT ONLY WITH FORMS IN WINDOW MODE.

It doesn't seem to work for Foms in tab mode... Unless you check ''use DB icon for Fom and Report'' but then they all have the same icon.

I'd really appriciate if anyone finds a way to do this in tab mode.
 

isladogs

CID VIP
Local time
Today, 11:27
Joined
Jan 14, 2017
Messages
14,406
The code provided by Oldsoftboss works BUT ONLY WITH FORMS IN WINDOW MODE.

It doesn't seem to work for Foms in tab mode... Unless you check ''use DB icon for Fom and Report'' but then they all have the same icon.

I'd really appriciate if anyone finds a way to do this in tab mode.

Agree with your observations.
You can have individual form icons in overlapping windows mode but AFAIK its not possible in tabbed document mode as every tab has to have the same properties. However I don't use that mode so may be proved wrong.

I played with the form icon code some time ago but in my experience end users never notice the form icon so its a bit of a waste of time and effort setting it anyway.
 

Users who are viewing this thread

Top Bottom