Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use AppTitle in Form 1

Status
Not open for further replies.

TrekBiker

Technical User
Nov 26, 2010
334
GB
I want to include the database App Title in a form.

I'm using VBA to enter a new Title, like this

Code:
    Dim obj As Object
    Dim dbs As Object
    Const conPropNotFoundError = 3270

    On Error GoTo ErrorHandler
    Set dbs = CurrentDb
    
   'Change title bar.
    dbs.Properties!AppTitle = InputBox("Version")
    Forms!Switchboard.DBVersion = dbs.Properties!AppTitle
    
   'Update title bar on screen.
    Application.RefreshTitleBar
    Exit Sub

ErrorHandler:
    If Err.Number = conPropNotFoundError Then
        Set obj = dbs.CreateProperty("AppTitle", dbText, "Contacts Database")
        dbs.Properties.Append obj
    End If
    Resume Next

I can't now get the data source right for a text box on the other form. Using dbs.Properties!AppTitle isn't allowed.
 
I apparently borrowed some code from the internet somewhere a little over a year ago that adds the title property (towards the end)...

Having looked at it and poking around with the immediate window, try...

Code:
dbs.Containers!Databases.Documents!MSysDb.properties("AppTitle")

The one caveat I have with the below code that sets it is that the change does not persist which is usually ok with me since I run it at startup. On the flip side, it gets tricky to keep track of where your VBA window goes if its name does not match the main application instance and you have multiple sessions running. I find I usually end up setting it manually eventually.

Code:
Public Function SetAppTitle(strPropValue As String) As Boolean
'Sets the Application Title property and creates it if it is missing
'This is the same as the Application title found under Current Database (tab), find it Under Options on the File ribbon


'Borrowed from the internet
On Error GoTo ErrHandle

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

    Set db = CurrentDb

    Set doc = db.Containers!Databases.Documents!MSysDb 'Added Note: Best I can tell this is just where Access decides to put this particular property when it is set, it is an internal Access System document
    doc.Properties.Refresh

    Set prp = doc.Properties("AppTitle")
    prp.Value = strPropValue

    SetAppTitle = True

ExitHere:
    On Error Resume Next
    'Show the change on the Title Bar
    Application.RefreshTitleBar
    Set prp = Nothing
    Set doc = Nothing
    Set db = Nothing
    Exit Function

ErrHandle:
    'If property not found, create it.
    If Err = 3270 Then
        Set prp = db.CreateProperty("AppTitle", dbText, strPropValue)
        db.Containers!Databases.Documents!MSysDb.Properties.Append prp
        SetAppTitle = True
    Else
        MsgBox "Error #" & Err.Number & " " & Err.Description _
        & "In Procedure SetAppTitle"
    End If
    Resume ExitHere

End Function
 
Thank you so much for responding lameid. As with most things there isn't a quick fix but I'll give the code you supplied a go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top