Access API wrapper controlling another AccessDB's form

J

John Keith

I have a DB form that uses some mainframe data that is auto refreshed into a
DB stored on a network. This table is then linked to from a front-end DB
that has a search form (using unbound text boxes to define the search
criteria)

As the Search is filtered onto the form... the matching data rows appear in
the detail of a continuous form. The OnClick event(s) are set to return the
selected key to a calling control (when other forms of the same database use
it)... However, the new part I am attempting to set up will allows the
clicked-on-key to be passed over to a mainframe emulator running a CICS
application that will then show the selected key. This works just fine ...
as long as the user then alt-tabs or somehow manually gets back to the search
form when they want to lookup a new record.

I have added a clickable button on the mainframe emulator that can OPEN an
executable, which I use to open an access database. Since this command by
itself can't check to see if the Lookup-DB/search form was already opened. I
am making it open a seperate access DB that has API calls to test for the
search db/form already open and then swapping to that form. (Or) Open the
SearchDB if necessary and open the search-form. (Or) Just open the form if
the SearchDB was already open.

I am having an issue with the CurrentDatabase vs. the SearchDB and finding
the Searchform to open. Here is my function that I am attempting to run:
GotoStudentLookup() is being called in an autoexec macro

Option Compare Database
Option Explicit
Dim appAccess As Access.Application
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA"
(ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2
As String) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal hwnd As Long)
As Long
Function FindSL() As Long
Dim hWndDesktop As Long
hWndDesktop = GetDesktopWindow
FindSL = FindWindowEx(hWndDesktop, 0, "OFormPopup", "frmStudentSearch :
Form")
End Function
Function FindDB() As Long
Dim hWndDesktop As Long
hWndDesktop = GetDesktopWindow
FindDB = FindWindowEx(hWndDesktop, 0, "ODb", "StudentLookup : Database
(Access 2000 file format)")
End Function
Function GotoStudentLookup()
Dim hwnd As Long
Const sFilepath As String = "C:\Documents and Settings\jkeith\My
Documents\TEST\StudentLookup.mdb"
hwnd = FindSL
If hwnd > 0 Then
'Student Search form exists now
BringWindowToTop (hwnd)
Application.CloseCurrentDatabase
Else
'Search was not loaded.. check for DB
hwnd = FindDB()
If hwnd > 0 Then
'DB loaded but form needs to be shown
DoCmd.OpenForm "frmStudentSearch", acNormal
hwnd = FindSL
BringWindowToTop (hwnd)
Application.CloseCurrentDatabase
Else
'StudentLookup DB wasn't found either... Load it
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase sFilepath, True
appAccess.DoCmd.OpenForm "frmStudentLookup", acNormal
hwnd = FindSL
BringWindowToTop (hwnd)
Application.CloseCurrentDatabase
End If
End If
End Function

So far, I am just starting the test with the 3rd condition:
StudentLookup.mdb is NOT open to start with...

appAccess.DoCmd.OpenForm "frmStudentLookup", acNormal <- is not finding the
form; I guess because it is still looking in the CurrentDatabase, not the one
I try to point to with appAccess

The Open just previous; seems to execute ok, but the database does not
appear in the taskbar; I looked at the properties under appApplication's
CurrentProject tree and did find the reference to the frmStudentLookup; but I
could not find how to use that as a reference to OPEN the form.

Am I going about this in the right way (or A way that will work?) the idea
is to have a "seemless" flow from the mainframe emulator back to the
searchform via a clickable-search-button
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top