First Published 6 Aug 2024
I have written several articles about application icons including ways of hiding the taskbar icon for Access apps.
For example, see Control the Application Interface and Hide the Taskbar Icon
I have also included code to create application icons as part of other example apps.
However, until now I have never written an article specifically on this topic as I realsed when contacted by a German developer recently. Time to put that right!
Access makes it easy to set the application title and/or icon from the Current Database section of Access Options
Doing this adds the values as new database properties AppTitle and AppIcon.
However, the application icon property only takes effect if the application title property is also set as shown above.
The application icon can optionally be used as an icon for each form and report
Each of these properties can also be set using code. Where the property doesn't exist, it is first created then the property value is applied.
Once agasin, the AppTitle must be set before setting the AppIcon has any effect.
Place the following code in a standard module:
CODE:
Option Compare Database
Option Explicit
Function UpdateAppTitle()
On Error GoTo SetProperty
'This handles err 3270 where the property doesn't exist
Dim strText As String
Dim Prop As Property
'set the app title to any suitable value
'strText = "MyDatabaseTitle"
'or set it to the file name with the .accdb/.accde removed
strText = Left(CurrentProject.Name, InStr(CurrentProject.Name, ".") - 1)
'add the property & set value
Set Prop = CurrentDb.CreateProperty("AppTitle", dbText, strText)
CurrentDb.Properties.Append Prop
Application.RefreshTitleBar
SetProperty:
On Error GoTo ErrorHandler
'Update Application Title
CurrentDb.Properties("AppTitle").Value = strText
Application.RefreshTitleBar
ErrorHandler:
Exit Function
End Function
=================================
Function UpdateAppIcon()
On Error GoTo SetProperty
'This handles err 3270 where the property doesn't exist
Dim IconPath As String
Dim Prop As Property
'set the icon path as appropriate
IconPath = CurrentProject.Path & "\play2.ico"
'add the property & set value
Set Prop = CurrentDb.CreateProperty("AppIcon", dbText, IconPath)
CurrentDb.Properties.Append Prop
'older versions of Access (e.g. A2010) allowed the custom icon to be displayed in the title bar
Application.RefreshTitleBar
SetProperty:
On Error GoTo ErrorHandler
'Update Application Icon
If Dir(IconPath) <> "" Then
CurrentDb.Properties("AppIcon").Value = IconPath
Application.RefreshTitleBar
End If
ErrorHandler:
Exit Function
End Function
Typical usage:
Run the code from the Load event of a startup form or from an Autoexec macro
Similar code can be used to set other custom database properties
Download:
Click to download an example app with the above code and an icon file
SetAppIcon Approx 0.4 MB ACCDB (zipped)
Download and unblock the zip file. For more details, see my article: Unblock downloaded files by removing the Mark of the Web
Unzip and save the ACCDB file to a trusted location
Feedback
Please use the contact form below to let me know whether you found this article interesting/useful or if you have any questions/comments.
Please also consider making a donation towards the costs of maintaining this website. Thank you
Colin Riddington Mendip Data Systems Last Updated 6 Aug 2024
Return to Code Samples Page
|
Return to Top
|