Edwin van Ree said:
Hi Dirk,
Thanks heaps for your reply and sorry for the confusion in the terms;
I recently converted my entire database from DAO to ADODB.
I am still confused about the code I use, which I found in various
different examples. When I start the application the property is
created and the application title reflects the change. Subsequent
updates however will not change the title bar. The original code is:
Public Function funWindowAddAppProperty(strName As String, varValue As
Variant) As Integer
Const conINVALID_PROPERTY_REFERENCE As Integer = 2455
On Error GoTo AddProp_Err
CurrentProject.Properties(strName) = varValue
Application.RefreshTitleBar
funWindowAddAppProperty = True
AddProp_Bye:
Exit Function
AddProp_Err:
If Err.Number = conINVALID_PROPERTY_REFERENCE Then
CurrentProject.Properties.Add strName, varValue
Resume Next
Else
funWindowAddAppProperty = False
Resume AddProp_Bye
End If
End Function
I changed the function as follows (and I have to ref DAO for this),
which works also with updates. It still uses the
CurrentProject.Properties.Add to initially create the property. Am I
mixing objects or what? My database is a .mdb file.
Public Function funWindowAddAppProperty(strName As String, varValue As
Variant) As Integer
Const conINVALID_PROPERTY_REFERENCE As Integer = 2455
Dim prpCurrent As AccessObjectProperty
Dim obj As Object
Dim dbs As DAO.Database
On Error GoTo AddProp_Err
Set dbs = CurrentDb
dbs.Properties(strName) = varValue
Application.RefreshTitleBar
funWindowAddAppProperty = True
AddProp_Bye:
Exit Function
AddProp_Err:
If Err.Number = conINVALID_PROPERTY_REFERENCE Then
CurrentProject.Properties.Add strName, varValue
Resume Next
Else
funWindowAddAppProperty = False
Resume AddProp_Bye
End If
End Function
I don't believe that that first version of the function ever did update
the title bar. I wouldn't expect it to, and I just tested it in a new
Access database, and it had no effect on the title bar.
The second version of the function will work, provided that the AppTitle
property has already been created; for example, by entering something
for it in the Tools -> Startup... dialog. However, if the property has
not yet been created, then the function won't work, because the
error-handling code creates the wrong property. Feel free to try that
in a new database and prove me wrong.
In an .mdb file, I believe the code you need to use DAO both to create
the property if it doesn't exist, and to change it if it does. You can
do this without actually referencing DAO, if you want to use late
binding, but you'll still be using DAO.
Here's an early-binding version:
'----- start of code -----
Public Function funWindowAddAppProperty( _
strName As String, _
varValue As Variant) _
As Integer
Const conINVALID_PROPERTY_REFERENCE As Integer = 3270
Dim dbs As DAO.Database
On Error GoTo AddProp_Err
Set dbs = CurrentDb
dbs.Properties(strName) = varValue
Application.RefreshTitleBar
funWindowAddAppProperty = True
AddProp_Bye:
Exit Function
AddProp_Err:
If Err.Number = conINVALID_PROPERTY_REFERENCE Then
dbs.Properties.Append dbs.CreateProperty(strName, dbText,
varValue)
Resume Next
Else
funWindowAddAppProperty = False
Resume AddProp_Bye
End If
End Function
'----- end of code -----
Note that this masquerades as a general-purpose function, but it isn't,
really, because it assumes that the property to be added is text,
without receiving any argument to tell it so.