?
Solved

VB2005 Express Edition - give focus to MS Access Application

Posted on 2007-03-21
4
Medium Priority
?
208 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 750 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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.
Suggested Courses
Course of the Month9 days, 8 hours left to enroll

762 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