Solved

VB2005 Express Edition - give focus to MS Access Application

Posted on 2007-03-21
4
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 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