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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

set app icon with vba code 2

Status
Not open for further replies.

Pampers

Technical User
Apr 7, 2004
1,300
AN
Hi everyone,
I've got the next code in a closed thread by LarrySteele (Programmer) 20 Oct 06 12:11. He gives a function to set the application icon through code.
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:

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


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

ChangeProperty "AppIcon", dbText, Access.CurrentProject.Path & "Icon1.ico"
HTH,
Larry

I used Larry's code, no error but also no icon appearing. What am I doing wrong. This is the code I use in a form load (login screen).

Code:
ChangeProperty "AppIcon", dbText, Access.CurrentProject.Path & "daicon.ico"

Any ideas?




Pampers [afro]
Keeping it simple can be complicated
 
You will need a backslash. You will also need to refresh the titlebar.

ChangeProperty "AppIcon", dbText, Access.CurrentProject.Path & "[red]\[/red]daicon.ico
 
Howdy Pampers . . .

Try this:
Code:
[blue]Public Sub SetAppIcon(IconPath As String)
   Dim db As DAO.Database, prp As DAO.Property

On Error GoTo GotErr
   
   Set db = CurrentDb
   
   db.Properties("AppIcon") = IconPath 'Attempt to assign
   Application.RefreshTitleBar 'Update On Screen!

Exit Sub

GotErr:
   If Err.Number = 3270 Then 'property doesn't exist!
      Set prp = db.CreateProperty("AppIcon", dbText, IconPath)
      db.Properties.Append prp 'New property set!
   Else
      MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
   End If
   
   Resume Next

End Sub[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Hi guys,
Nice to hear from you again.
Both solutions work fine. Didn't know about the refresh title bar (and yes, forgot the backslash, tx remou).
Last question. If I want to set the icon also for forms and reports (the checkbox in the startup), how can I do that...

Pampers [afro]
Keeping it simple can be complicated
 
Tnx Remou,
Was looking for that page, seen it somewhere, but couldn't find it anymore. It is for MS Access 2000, and misses the checkbox to set the icon for all forms and reports...
Anyway, a pinky for the both.


Pampers [afro]
Keeping it simple can be complicated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top