[AccessD] Getting Access Back On Top

Heenan, Lambert Lambert.Heenan at chartisinsurance.com
Wed Sep 8 14:42:04 CDT 2010


You want to get Access back on top, so sAppName (poor choice of variable name I admit) is all or part of the text in the Access window title bar. 

Lambert

-----Original Message-----
From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin
Sent: Wednesday, September 08, 2010 2:29 PM
To: 'Access Developers discussion and problem solving'
Subject: Re: [AccessD] Getting Access Back On Top

Lambert:

Thanks but I can't get it to work.   Calling ActivateWindowWithTitle what
should I pass to it in sAppName?

Meanwhile I modified the delete code to:

    For Each olContactItem In olContacts
        olContactItem.Delete
        DoEvents
    Next

And each time I call it, it deletes about 1/2 the contacts.  Very strange.
Anyone know why it should do that?

MTIA

Rocky

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Heenan, Lambert
Sent: Wednesday, September 08, 2010 10:38 AM
To: Access Developers discussion and problem solving
Subject: Re: [AccessD] Getting Access Back On Top

A few API calls can do that...


Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _ ByVal wCmd As Long) As Long

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _ (ByVal hwnd As Long, ByVal lpString As String, ByVal CCh As Long) As Long

Private Declare Function GetWindowTextLength Lib "user32" Alias _ "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Private Declare Function IsWindowVisible Lib "user32" _ (ByVal hwnd As Long) As Long



'GetWindow() constants
    Private Const GW_HWNDFIRST = 0
    Private Const GW_HWNDLAST = 1
    Private Const GW_HWNDNEXT = 2
    Private Const GW_HWNDPREV = 3
    Private Const GW_OWNER = 4
    Private Const GW_CHILD = 5
    Private Const GWL_HWNDPARENT = (-8)

    Private Const GWW_HWNDPARENT = (-8)

Private Function FindAppWindow(sAppTitle As String, hWndStart As Long) As Long
    'Finds a Window handle by its (partial) Title.
    'Only top level windows that have WS_VISIBLE style are
    'searched.
    ''''''''''''''''''''''''''''''''''''''''''''''''
    'sAppTitle - string that is contained in the Window title.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    'On success returns the hWnd of the window that contains the
    'sAppTitle string and copies the Complete Title into sAppTitle;
    'Otherwise returns 0.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

    Dim CurrWnd As Long
    Dim Length As Long
    Dim TaskName As String
    Dim lPos As Long

    CurrWnd = GetWindow(hWndStart, GW_HWNDFIRST)

    While CurrWnd <> 0
        If CurrWnd <> hWndStart And (0 <> IsWindowVisible(CurrWnd)) And (0 = GetWindow(CurrWnd, GW_OWNER)) Then
            'Find the length of the Title
            Length = GetWindowTextLength(CurrWnd)

            'Does the Window have any title
            If Length > 0 Then
                'Allocate enough memory for the text
                TaskName = Space$(Length + 1)
                'Get the title text of the window
                Length = GetWindowText(CurrWnd, TaskName, Length + 1)
                'Get the Window's title
                TaskName = Left(TaskName, Len(TaskName) - 1)

                'Check if it is the window we are looking for
                If InStr(1, TaskName, sAppTitle) > 0 Then
                    'We found it
                    FindAppWindow = CurrWnd
                    sAppTitle = TaskName
                    Exit Function
                End If
           End If
        End If
        'Get next window handle
        CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
        DoEvents
    Wend
End Function


Sub ActivateWindowWithTitle(sAppName As String) Dim hwnd As Long


    hwnd = FindAppWindow(sAppName, Application.hWndAccessApp)

    If hwnd <> 0 Then
        'Program is running
        'Send the keys

        'Activate the App
        AppActivate sAppName

        'Send Kyes

    End If

End Sub
    


HTH

Lambert 

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Rocky Smolin
Sent: Wednesday, September 08, 2010 12:36 PM
To: 'Access Developers discussion and problem solving'
Subject: [AccessD] Getting Access Back On Top

Dear List:

I have written a routine for a client to transfer their contact information from their database to a folder in Outlook.  The first I do is pop up the folder selector so that they can select the contact folder that they want to transfer their contacts into.  However, when the folder selector dialog box pops up, Outlook is has the focus.  After they select the folder, Outlook is still on top and they have to alt-Tab to get back to Access.  Is there a way in Access to get the access app back on top?

Second problem is that I delete all of the contacts in the target folder before the transfer using: 

    ' delete all the current contacts
    For Each olContactItem In olFolder.Items
        olContactItem.Delete
    Next

where: 

Dim olContactItem As outlook.ContactItem Dim olFolder As outlook.MAPIFolder


The loop takes a while to run but after it's done the contacts are still in the folder.  Can anyone see what I'm doing wrong here?

MMTIA,

 

Rocky Smolin

Beach Access Software

858-259-4334

Skype: rocky.smolin

www.e-z-mrp.com <http://www.e-z-mrp.com/> 

www.bchacc.com <http://www.bchacc.com/> 

 

 


--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com

--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list