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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reference Application title in VBA 2

Status
Not open for further replies.

JoeMicro

Technical User
Aug 24, 2007
76
CA
Hi,

is there any way to get the application title from another file (for instence my database file) in a msgbox or txtbox?

thanks,
joe
 
This function will return the title shown on the window title bar:
Code:
Option Compare Database
Option Explicit

Public Declare Function MMC_apiGetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lbString As String, ByVal cch As Long) As Long

Public Function MMC_GetWindowText(Optional varWHandle As Variant) As String

    Dim lngWHandle As Long
    Dim lngNoChars As Long
    Dim strText As String
    
    strText = Space(255)
    
    If (IsMissing(varWHandle)) Then
        lngWHandle = hWndAccessApp
    Else
        lngWHandle = varWHandle
    End If
    
    lngNoChars = MMC_apiGetWindowText(lngWHandle, strText, Len(strText) - 1)
    MMC_GetWindowText = Left(strText, lngNoChars)

End Function
 
Thanks FancyPrairie,

this works great with my running file,

now how do i get the same thing from another file.

like the application title of the file to which the tables in the current file are linked?

Joe
 
The title is a property of the database.

Code:
Public Sub ListAppTitle()
    '6 = linked tables
    strSQL = "SELECT Database, Name FROM MsysObjects WHERE Type=6"
    Set rs = CurrentDb.OpenRecordset(strSQL)
    
    Do While Not rs.EOF
    Set db = OpenDatabase(rs!Database)
    On Error Resume Next
    prpTitle = db.properties("AppTitle")
    If Err.Number <> 0 Then
        prpTitle = "N/A"
        Err.Clear
    End If
    
    Debug.Print rs!Name; "  "; prpTitle
    
    rs.MoveNext
    Loop

End Sub
 
thanks guys

thet did the job

thanks again

Joe
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top