Thursday, May 03, 2007

Keep Your Custom Access Application Icon Loaded

The Access StartUp dialog file path entry for a custom icon is hard-coded, so if you distribute your application and the absolute path is not be replicated in the user's PC, your custom icon will not load with your database.

The following code in a module will allways load your custom Icon provided the ICO file is in the same folder as your application database:

Option Compare Database
Option Explicit

Public Function fnAddAppIconProp()
'Call this function from the OnLoad Event of your StartUp form

Dim intX As Integer
Const DB_Text As Long = 10
intX = AddAppProperty("AppIcon", DB_Text, CurrentProject.Path & _
"\myapp.ico")
Application.RefreshTitleBar

End Function

Function AddAppProperty(strName As String, varType As Variant, varValue _
As Variant) As Integer

Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270

On Error GoTo AddProp_Err

Set dbs = CurrentDb
dbs.Properties(strName) = varValue
AddAppProperty = True

AddProp_Exit:

Exit Function

AddProp_Err:

If Err = conPropNotFoundError Then
Set prp = dbs.CreateProperty(strName, varType, varValue)
dbs.Properties.Append prp
Resume
Else
AddAppProperty = False
Resume AddProp_Exit
End If

End Function

No comments: