Solved

VB2005 Express Edition - give focus to MS Access Application

Posted on 2007-03-21
4
196 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
ID: 18765408
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
ID: 18769827
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
ID: 18779178
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
ID: 18791131
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

730 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