In your Access application you can set an application icon to be used in the title bars for your forms. Access allows you to hard code the filepath into the Startup settings. But what if you need to move the icon, or the application?
You'll need to update the startup file location. Or, you can set it dynamically, and forget about it.
The following code snippet will set up the application icon feature to use an image from the same path as the database file. So all you need to do is place the file you want to use for an image in the same folder as the database, and this code will pick up the image and use it as the icon for your database. Now you can move your application to another computer or another folder, and as long as you move the image with it, it will always get picked up and used as the application's icon.
What I do is put this code in the Form_Load Event of the startup form that is displayed when my application starts.
' set up application icon and form/report icon
' based on http://tinyurl.com/lpch2l and http://tinyurl.com/klytxr
Const APP_LOGO_FILE As String = "MyFile.bmp"
Dim prp As Property
With CurrentDb
.Properties("UseAppIconForFrmRpt") = True
' try to create property, if it doesn't exist
On Error Resume Next
Set prp = .CreateProperty("AppIcon", dbText, CurrentProject.Path & "\" & APP_LOGO_FILE)
If Err = 0 Then ' prop didn't exist before
.Properties.Append prp
Else
On Error GoTo 0
.Properties("AppIcon") = CurrentProject.Path & "\" & APP_LOGO_FILE
End If
End With
Application.RefreshTitleBar
(ps- You can do the same thing with images, so they aren't stored inside the database.)
What I found out the hard way was that if the AppIcon property isn't set, it doesn't exist. So the code above will try to create the property first. If the property does in fact exist, just set it. Here's how I found out it didn't exist:
Sub checkprops() Dim prp As Property For Each prp In CurrentDb.Properties Debug.Print prp.Name & " - " & prp.Value Next prp End Sub
Follow Me