Solved

VB2005 Express Edition - give focus to MS Access Application

Posted on 2007-03-21
4
179 Views
Last Modified: 2012-05-05
Hi,
I have developed a VB2005 Express Edition application that (as part of further development) now needs to be able open and give focus to an MS Access 2003 utility that is already programmed, up and running and in use by other users.

Currently, my program will successfully fire the Access program (via the code shown below), but once the Access program has processed the specific AutoExec.DVT macro, Access disappears from the screen and is then no longer part of the current running applications, although a process MSACCESS can be seen within the Task Manager Processes window.  

What I would like to do, is have the Access utility fire up, give full focus to Access and then when Access is closed, our users can continue with the VB Program in the normal way.  This query is not related to problems of sql, datatables, or queries, but to simply using another utility.

Thank you.
Regards,
Keith

    Private Sub StatisticalProcessControl()
        Dim conn As Access.Application
        conn = New Access.Application

        With conn
            .OpenCurrentDatabase("C:\Documents and Settings\kblakesley\" & _
            "My Documents\DATABASES\Under Development\DVTCamera\SPCProgram\" & _
            "SPCProgram2003.mdb", False)
            .DoCmd.RunMacro("AutoExec.DVT")
        End With

    End Sub
0
Comment
Question by:keithedwardb
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
Comment Utility
Well looking at your code, you are not closing the instance of access

u need to do this

conn.CloseCurrentDatabase
set conn = nothing

this should then ensure that the process is not left running

to make it visible, u could try this

conn.visible = true
0
 

Author Comment

by:keithedwardb
Comment Utility
Hi rockiroads,
Thank you.  This answers the question nicely.  It opens up a few others but that's for another time.

Just a note on the above solution, the conn.CloseCurrentDatabase did close the session cleanly, but that was as soon as the Access database utility opened.  So I commented out the close line and the utility remained up, which is exactly as I wanted it. (using the .visible = true).
However, I am thinking about a Do While loop to check a flag in the database table to say that the access utility is now closed, therefore proceed with the .CloseCurrentDatabase / conn = nothing lines.
Does this sound reasonable, or is there another way, please?

Thank you.
Regards,
Keith
0
 
LVL 65

Expert Comment

by:rockiroads
Comment Utility
Sorry about late reply. Got busy at work.

Now thats a pity that it closed straight away, I would of thought it would wait for the macro to run. Perhaps access just sends a message to the other db to run the macro

Did the macro run fully or it did not complete execution
0
 

Author Comment

by:keithedwardb
Comment Utility
Thanks for the follow up.
The macro did run fully (although this was only to run a simple screen message, before later development of the Access Db.)  The session seemed to time out after a couple of seconds - presumably the conn.closecurrentdb doing its job?
I have a work around that does work.  When the Db front end closes, I write a flag to a table in the BE db.  
Within the VB App, I have a DO WHILE loop that checks for the flag.  When it detects it, the system exits the loop and then runs the close line.

However, the only line that runs is conn=nothing.  I still have to comment out the conn=close... because when the app runs it reports an exception that says the connection doesn't / no longer exists (assuming that the act of closing Access from within itself severs the ties?)

I'm not sure what's really going on, but I have a solution - a bit messy perhaps, but, as usual, I have the bigger picture to worry about.  I'll mull it over in due course.  Thanks again.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now