Microsoft KB Archive/141618

= ACC: How to Use Visual Basic to Change Application Title (95/97) =

Article ID: 141618

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q141618



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article shows you how to use Visual Basic for Applications to change the title bar text, which is also referred to as the Application Title.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.



MORE INFORMATION
Unless you set the Application Title in the Startup dialog box to something different for your database, the default text that appears in the title bar is "Microsoft Access."

You can manually change the Application Title property of a database by clicking Startup on the Tools menu, and then typing a new name in the Application Title box. Then, whenever you open the database, the title bar text displays the name that you typed.

You can also use Visual Basic for applications to programmatically change the Application Title setting every time the database opens. As an example, the following steps demonstrate how to set the Application Title to the name of the current database and the name of the current user in the database:   Create a module and type the following procedures: Function SetApplicationTitle(ByVal MyTitle As String) If SetStartupProperty("AppTitle", dbText, MyTitle) Then Application.RefreshTitleBar Else Msgbox "ERROR: Could not set Application Title" End If     End Function

Function SetStartupProperty(prpName As String, _           prpType As Variant, prpValue As Variant) As Integer Dim DB As DATABASE, PRP As Property, WS As Workspace Const ERROR_PROPNOTFOUND = 3270

Set DB = CurrentDb

' Set the startup property value. On Error GoTo Err_SetStartupProperty DB.Properties(prpName) = prpValue SetStartupProperty = True

Bye_SetStartupProperty: Exit Function

Err_SetStartupProperty: 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 Bye_SetStartupProperty End Select End Function

Function CurrentMDB As String Dim i As Integer, FullPath As String FullPath = CurrentDb.Name ' Search backward in string for back slash character. For i = Len(FullPath) To 1 Step -1 ' Return all characters to the right of the back slash. If Mid(FullPath, i, 1) = "\" Then CurrentMDB = Mid(FullPath, i + 1) Exit Function End If        Next i      End Function   Create the following macro and save it as AutoExec: Macro Name Action ---

AutoExec   Runcode

AutoExec Actions ---     RunCode Function Name: =SetApplicationTitle(CurrentMDB &" - " & _             CurrentUser) NOTE: In the Function Name setting above, the underscore (_) at the end of the line is used as a line-continuation character. Remove the underscore from the end of the line when typing the Function Name setting. 

