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

Switched to window won't accept input

Status
Not open for further replies.

pullingteeth

Programmer
Sep 26, 2003
128
US
Hello, the following code (written in a macro language which can call out to the win32 API) switches from the user's window to an Access window ("tracking"), and activates a form with the "f5" key. In theory. It all works apart from the "f5" key, which doesn't seem to be accepted by the Access window; however, if I press "f5" myself after the macro has finished, it works (i.e. the window is at the front, has focus, and appears to be active). So where's the problem? Thanks in advance.

Code:
   dim ntsid as long
    dim y as long, tdbid as long

    ' get the NTS id
    ntsid = GetForegroundWindow

    ' get the     
    tdbid = FindWindow("", "Tracking")   
    if tdbid = 0 then
        msgbox "You haven't opened the database yet! Please do so now, login, " _
            & "and then click OK..."
        tdbid = FindWindow("", "Tracking")
        if tdbid = 0 then
            msgbox "Sorry, I still can't find the database. Your action won't " _
                & "be recorded. Run the macro again if you like."
            goto endAndLetThemFigureItOut
        end if
    else
        ' Close (minimize, deactivate) the nts window
        y = CloseWindow(ntsid)        
    end if
    
    ' Maximize the tracking db window
    y = ShowWindow(tdbid, 1)
    ' Bring it to the foreground so it can accept input
    y = SetForegroundWindow(tdbid)
    ' Update it, so it displays itself at the front
    y = UpdateWindow(tdbid)

'**********************************************************************************
'INPUT TO DB

    ' Pause for one second , so the users can see a message of the day if 
    ' there is one, etc
    pause 1
    sendkeys "{f5}"
 
I got it working by (strangely) setting the title of the window before sending keys. Any idea what side effect this is having?

Code:
    y = setWindowText(tdbid, "You are very happy")
    sendkeys "{f5}", true
    y = setWindowText(tdbid, "Tracking")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top