Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the Application Icon with code? 1

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
US
How can I set the Application Icon with code instead of in the StartUp window? On occasion the database is installed on different(mirrored)drives so I can't use the StartUp window to set the icon?

Thanks
 
I found some code that should do the trick but I am getting a Property Not Found error when I run the code. The function is run on the OnClose action of the splashscreen. strDBPath is a variable I set to the location of the backend.

Can anybody see my error? Thanks.

Public Function AssignIcon()
Dim db As Database
Dim strIconPath As String

Set db = CurrentDb
strIconPath = strDBPath & "Icon1.ico"
db.Properties("AppIcon").Value = strIconPath
Application.RefreshTitleBar

End Function
 
Access doesn't expose this property for VBA to use. You'll have to append the property if it's not already available, and you determine if the property's available by trapping for error 3270.

Here's a function I've used in the past:

[tt]Function ChangeProperty(strPropName As String, varPropType As String, varPropValue As Variant) As Integer

Dim dbs As DAO.Database
Dim prp As DAO.Property

Set dbs = CurrentDb
On Error GoTo PROC_ERROR

dbs.Properties(strPropName) = varPropValue
ChangeProperty = True

PROC_EXIT:
On Error Resume Next
Set prp = Nothing
Set dbs = Nothing
Exit Function

PROC_ERROR:
If Err.Number = 3270 Then
Set prp = dbs.CreateProperty(strPropName, varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else
ChangeProperty = False
Resume PROC_EXIT
End If
End Function
[/tt]

To use this function to change the icon, I would have the following in my startup procedure:

[tt]ChangeProperty "AppIcon", dbText, Access.CurrentProject.Path & "Icon1.ico"[/tt]

HTH,
Larry
 
Brilliant! It works great. Thanks for your help.

Cheers!,
Eddy
 



Hey Eddie,

You've been here at Tek-Tips over a year.

Posted 94 questions.

Got nearly 40 replys...

and only awarded ONE thank you???

Common, guy. You stated that Larry's post was

"Brilliant! It works great. "

Loosten up with a ...
[blue]
Thank LarrySteele
for this valuable post!
[/blue]



Skip,

[glasses] [red][/red]
[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top