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

ID: Q141618


The information in this article applies to:
  • Microsoft Access versions 7.0, 97


SUMMARY

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

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:

  1. 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 


  2. 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.



REFERENCES

For more information about changing the application title bar, search for "apptitle," and then "AppTitle Property" using the Microsoft Access 97 Help Index.

Additional query words:

Keywords : kbprg
Version : WINDOWS:7.0,97
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: October 13, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.