How to set the Application Title in VBA

P

Patrick Wolf

Hi,

is there a way to set the Application Title (the one you normaly set in
Startup) via VBA in Accesss 2003?

Thanks
Patrick
 
J

Jeff Conrad

in message:
is there a way to set the Application Title (the one you normally set in
Startup) via VBA in Access 2003?

Hi Patrick,

Place these functions in a new standard module, compile, and save:

'********Code Start*******
Public Function SetApplicationTitle(ByVal MyTitle As String)
On Error GoTo ErrorPoint

If SetStartupProperty("AppTitle", dbText, MyTitle) Then
Application.RefreshTitleBar
Else
MsgBox "ERROR: Could not set Application Title"
End If

ExitPoint:
Exit Function

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function

Public Function SetStartupProperty(prpName As String, _
prpType As Variant, prpValue As Variant) As Integer
On Error GoTo ErrorPoint

Dim db As DAO.Database
Dim prp As DAO.Property

Const ERROR_PROPNOTFOUND = 3270

Set db = CurrentDb()

' Set the startup property value.

db.Properties(prpName) = prpValue
SetStartupProperty = True

ExitPoint:
' Cleanup code
On Error Resume Next
Set db = Nothing
Exit Function

ErrorPoint:
Select Case Err
' If the property does not exist, create it and try again.
Case ERROR_PROPNOTFOUND
Set prp = db.CreateProperty(prpName, prpType, prpValue)
db.Properties.Append prp
Resume
Case Else
SetStartupProperty = False
Resume ExitPoint
End Select

End Function
'********Code End*******

(Make sure you have a reference to the DAO object library)

From code to change the title you would just do this:

SetApplicationTitle("New Title Here")

Hope that helps,
 
P

Patrick Wolf

Hi Jeff,

thanks very much for your code it works perfectly in an MDB file.
Unfortunatly I forgot to mentioned that I am using an Access Project ADP
file and the code doesnt work there (I guess because its not based on DAO).
Do you have any idea what I would need to change in your code?

Thanks a lot
Patrick
 
M

Mark M

I don't have any experience with ADP, but...
If you first set the title using "Tools|Startup", then the title property
will be created and all you would need to do is have a little routine like
this in a standard module.

Sub ChangeTitle(NewTitle As String)
CurrentDb.Properties!AppTitle = NewTitle
Application.RefreshTitleBar
End Sub

And then to use it, just call the routine like: Call ChangeTitle("The New
Title")

Some people like to change the title based on a value in the current record,
like to include the employee name to reinforce to the user which record
they're on. If you don't need to change the title all the time, just set
the AppTitle property to whatever you want instead of calling the routine
from another place. So, you could just add the two lines above (the
AppTitle line and the RefreshTitleBar line) to any code you're running on
startup.
 
P

Patrick Wolf

Hi Marc,

thanks for your answer. It seems like an Access Project hasnt got a
CurrentDb (it is not set).
But it has a CurrentProject so CurrentProject.Properties("AppTitle") holds
the current title.
The only thing is that if I set it to a new value it gives back false and
doesn't change the Title :(.

Thanks and all the best
Patrick
 

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