Microsoft Knowledge Base Email Alertz

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

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 210169 - Last Review: June 24, 2004 - Revision: 2.0

ACC2000: How to Use Visual Basic to Change the Application Title

This article was previously published under Q210169
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies only to a Microsoft Access database (.mdb).

SUMMARY

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

MORE INFORMATION

NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

Unless you set the Application Title property 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 displays the name that you typed.

You can also use Visual Basic for Applications to programmatically change the Application Title every time the database opens. As an example, to set the Application Title to the name of the current database and the name of the current user in the database, follow these steps:
  1. Create a module and type or paste 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 DAO.DATABASE, PRP As DAO.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 AppTitle:
    Action
    --------
    RunCode

    AppTitle Actions
    -----------------
    RunCode
    Function Name: SetApplicationTitle(CurrentMDB() & " - " & CurrentUser)
  3. Run the macro.

    Notice that the text in the title bar has changed to reflect the names of the database and the current user.

REFERENCES

For more information about changing the application title bar, click Microsoft Access Help on the Help menu, type apptitle property in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

APPLIES TO
  • Microsoft Access 2000 Standard Edition
Keywords: 
kbhowto kbprogramming KB210169
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate