RefreshTitleBar and ADODB

E

Edwin van Ree

When I update the (existing) AppTitle property with DAO code and do a
Application.RefreshTitleBar the change is reflected in the titlebar. When I
do the same with ADODB code: CurrentProject.Properties("AppTitle") = "new
value", the change is not displayed after the Application.RefreshTitleBar.
The value is updated in the property, when I do a debug.print of the property
it shows the new value.

Anyone has the same problem? Is it a bug in Access 2003?
 
D

Dirk Goldgar

Edwin van Ree said:
When I update the (existing) AppTitle property with DAO code and do a
Application.RefreshTitleBar the change is reflected in the titlebar.
When I do the same with ADODB code:
CurrentProject.Properties("AppTitle") = "new value", the change is
not displayed after the Application.RefreshTitleBar. The value is
updated in the property, when I do a debug.print of the property it
shows the new value.

Anyone has the same problem? Is it a bug in Access 2003?

Note: CurrentProject is not an ADO object, so it's a misnomer to refer
to the sort of code you're talking about as "ADODB code". Regardless,
CurrentProject and CurrentDb are completely different objects, not the
same thing being referred to by different names. Even if you add an
"AppTitle" property to the Properties collection of CurrentProject,
Access will not take the Application Title from that property.

The help file entry for "AppTitle property" says:
<quote>
To set the AppTitle property by using a macro or Visual Basic, you must
first either set the property in the Startup dialog box once or create
the property in the following ways:

* In a Microsoft Access database (.mdb), you can add it by using the
CreateProperty method and append it to the Properties collection of the
Database object.

* In a Microsoft Access project (.adp), you can add it to the
AccessObjectProperties collection of the CurrentProject object by using
the Add method.
</quote>

I find that, in an .mdb file, CurrentProject does not appear to have an
AccessObjectProperties collection, so I don't think you can set this
property by way of CurrentProject unless you are working with an .adp,
not an .mdb.
 
E

Edwin van Ree

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
 
D

Dirk Goldgar

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.
 

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

Top