Option Compare Database   'Use database order for string comparisons
Option Explicit

Const GW_CHILD = 5
Const GW_HWNDNEXT = 2

Declare Sub SetWindowText Lib "User" (ByVal hWnd As Integer, ByVal lpString As String)
Declare Function SetActiveWindow Lib "User" (ByVal hWnd As Integer) As Integer
Declare Function GetActiveWindow Lib "User" () As Integer
Declare Function GetDesktopWindow Lib "User" () As Integer
Declare Function GetCurrentTask Lib "Kernel" () As Integer
Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
Declare Function GetParent Lib "User" (ByVal hWnd As Integer) As Integer
Declare Function IsWindowVisible Lib "User" (ByVal hWnd As Integer) As Integer

Function NameAccess (strName As String)
    Dim hdlWindow As Integer
    Dim hdlActive As Integer
    Dim strText As String
    Dim hdlTask As Integer
    Dim hdlCurrent As Integer

    hdlWindow = GetDesktopWindow()
    hdlWindow = GetWindow(hdlWindow, GW_CHILD)
    Do Until hdlWindow = 0
	If GetWindowTask(hdlWindow) = GetCurrentTask() Then
	    If IsWindowVisible(hdlWindow) And GetParent(hdlWindow) = 0 Then
		Exit Do
	    End If
	End If
	hdlWindow = GetWindow(hdlWindow, GW_HWNDNEXT)
    Loop

    If hdlWindow <> 0 Then
	hdlActive = GetActiveWindow()
	varRetCode = SetActiveWindow(hdlWindow)
	SetWindowText hdlWindow, strName
	varRetCode = SetActiveWindow(hdlActive)
    End If
End Function

