Application Icon

  • Thread starter Thread starter Ian Davies
  • Start date Start date
I

Ian Davies

Hello

Is there a way of setting the application icon from code, or somehow
ensuring the pathway to it isnt lost if the database is moved to a different
location?

Thanks in advance
Ian
 
Assuming the AppIcon property exists (i.e. you have set the icon at some
stage):

strIconFile = strPath & strIconFile
If Dir$(strIconFile) <> "" Then
db.Properties("AppIcon") = strIconFile
Application.RefreshTitleBar
End If
 
Thanks for your code. Where should I put it.
At the moment I have the complete path to the icon set on the startup
window.
However, this is not dynamic
Ive tried making a function of your code and putting the function name in
the startup window but that didnt work

Ian
 
Ian, the code would typically go into the initialization routine of your
database.

I've assumed that:
1) You have a string variable that contains the path to the database file,
e.g.:
Dim strPath As String
strPath = CurrentProject.Path & "\"

2) You have the name of your icon file in another string variable, e.g.:
Dim strIconFile As String
strIconFile = "MyIcon.ico"

3) You have also declared a database variable
Dim db As DAO.Database
Set db = dbEngine(0)(0)

If you have all those in place, and your function still does not work, what
error do you receive?
 
Ive put the following code in the 'on open' event of my startup form. Is
this the correct place to put it?
I get the error message 'property not found'

Dim db As DAO.Database
Dim strIconFile As String
Dim strPath As String

Set db = DBEngine(0)(0)
strPath = CurrentProject.Path & "\"
strIconFile = "RWicon.ico"

strIconFile = strPath & strIconFile
If Dir$(strIconFile) <> "" Then
db.Properties("AppIcon") = strIconFile
Application.RefreshTitleBar
End If


Ian
 
If the property is not found, you have not yet assigned an icon to this
database. You can do that programmtically with CreateProperty(), or--since
it only has to be done once--you can do it be assigning the icon manually
the first time. Go to:
Tools | Start Up | Application Icon
 
I dont think this is the case here. Ive had icons assigned in startup but
the link is broken if the database is moved. Do you need a pathway to the
icon in startup even when assigning programmatically.
Also is the code in the right place i.e. in on open event of startup form or
is there a better method?

ian
 
If you enter a value in via the menu, Access will include the path. The
point of that was to get Access to create the property for you.

If you want to create it programmtically you could use the code below.

The open event of the startup form is quite appropriate.

Function SetPropertyDAO(obj As Object, strPropertyName As String, intType As
Integer, varValue As Variant, Optional strErrMsg As String) As Boolean
On Error GoTo ErrHandler
'Purpose: Set a property for an object, creating if necessary.
'Arguments: obj = the object whose property should be set.
' strPropertyName = the name of the property to set.
' intType = the type of property (needed for creating)
' varValue = the value to set this property to.
' strErrMsg = string to append any error message to.

If HasProperty(obj, strPropertyName) Then
obj.Properties(strPropertyName) = varValue
Else
obj.Properties.Append obj.CreateProperty(strPropertyName, intType,
varValue)
End If
SetPropertyDAO = True

ExitHandler:
Exit Function

ErrHandler:
strErrMsg = strErrMsg & obj.Name & "." & strPropertyName & " not set to
" & varValue & ". Error " & Err.Number & " - " & Err.Description & vbCrLf
Resume ExitHandler
End Function

Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top