Solved

VB2005 Express Edition - give focus to MS Access Application

Posted on 2007-03-21
4
191 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 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