ACC: Changing Application Title Using Visual Basic (95/97)

Last reviewed: August 28, 1997
Article 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 describes how you can programmatically change the title bar text, also referred to as the Application Title, in Microsoft Access version 7.0 and 97 using Visual Basic for Applications.

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 you typed.

You can also programmatically change the Application Title setting every time the database opens by using Visual Basic. 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.

Keywords          : kbprg PgmHowTo
Version           : 7.0 97
Platform          : WINDOWS
Hardware          : x86
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.