Programatically set app icon

speakers_86

Registered User.
Local time
Today, 15:48
Joined
May 17, 2007
Messages
1,919
So I had this working fine, but after creating a new db and importing all objects to trouble shoot another issue, there is an error now.

It's throwing an error here:
Code:
CurrentDb.Properties("UseAppIconForFrmRpt") = 1

It's a property not found, which I 'fixed' with on error resume next.


Code:
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'The following calls the AddAppProperty Function defined below.  Changes the app title and icon.
'If using for the first time, must close and reopen to see effects on the form this is called from
 On Error Resume Next
 Dim intX As Integer
    Const DB_Text As Long = 10
    intX = AddAppProperty("AppTitle", DB_Text, "SER Database")
    intX = AddAppProperty("AppIcon", DB_Text, CurrentProject.path & "\icon.ico")
    CurrentDb.Properties("UseAppIconForFrmRpt") = 1
    Application.RefreshTitleBar

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
End Sub
'This changes the app icon and title
Function AddAppProperty(strName As String, _
        varType As Variant, varValue As Variant) As Integer
    Dim dbs As Object, prp As Variant
    Const conPropNotFoundError = 3270

    Set dbs = CurrentDb
    On Error GoTo AddProp_Err
    dbs.Properties(strName) = varValue
    AddAppProperty = True

AddProp_Bye:
    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_Bye
    End If
End Function
 
so what are you asking? how to fix it?

are you sure you have the right prop name? what is it? never seen that one?

if it's not there, simply add it with the ADD method. For instance, databases don't have the SHIFT bypass key property there by default, so MS tells us to add it:

http://office.microsoft.com/en-us/access-help/allowbypasskey-property-HA001232717.aspx

I would assume the fix for this would be to do the same thing.
 
Isn't that already happening in the AddProp_Err?

edit- I'll add a msgbox to see here in a little bit.
 
Because the error handling either isnt working or isnt being called. I'm receiving an unknown property error for "UseAppIconForFrmRpt".
 
Because the error handling either isnt working or isnt being called. I'm receiving an unknown property error for "UseAppIconForFrmRpt".

have you looped through the props and seen what is in there? VBA help has a page with code for looping the db's props and printing them. look up "properties collection" in there and you'll see it. first article.

have you looked this up too?

http://www.google.com/#sclient=psy&...gc.r_pw.&fp=e095642267568bf6&biw=1024&bih=681
 
this all pointed me in the right direction to do this for myself

I ended up with just this code, which i picked up elsewhere (tek tips). the last line, refreshtitlebar, I added, and this shows the change immediately


Code:
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

Sub seticon()
    ChangeProperty "AppIcon", dbText, CurrentProject.path & "\icon.ico"
    Application.RefreshTitleBar
End Sub
 
Last edited:
very nice. Thank you. I'll give that a try here in a little bit. I haven't actually messed with this in a couple days.
 
actually, speakers, my code looks very similar to yours, I think, on re-examining your code

Because you had some problems, I just looked around for a different version on the web, rather than try and debug something i didn't quite understand. you have the refreshtitlebar commmand as well.

So checking yours again, you report a problem with this line

CurrentDb.Properties("UseAppIconForFrmRpt") = 1

I am not sure exactly what this property does - but it just looks like you you probably need to create this property first, before you can use it, with another addapp line.
 
I forgot to tell you what the property does! It sets the icon for forms and reports to be that of the database icon. You can see it in the access options, right below where you set the location of the db icon is a checkbox.
 
It seems I have a solution. I followed these instructions to set the form and report icons.

As for the db title and app, I used the code from my original post, minus that one line that threw the error.
 

Users who are viewing this thread

Back
Top Bottom