Question

I have the following code:

Dim obj As New Access.Application
obj.OpenCurrentDatabase (CurrentProject.Path & "\Working.mdb")
obj.Run "Routine"
obj.CloseCurrentDatabase
Set obj = Nothing

The problem I'm experimenting is a pop-up that tells me Access can't set the focus on the other database. As you can see from the code, I want to run a Subroutine in another mdb. Any other way to achieve this will be appreciated.

I'm working with MS Access 2003.

This is an intermittent error. As this is production code that will be run only once a month, it's extremely difficult to reproduce, and I can't give you the exact text and number at this time. It is the second month this happened.

I suspect this may occur when someone is working with this or the other database.

The dataflow is to update all 'projects' once a month in one database and then make this information available in the other database.

Maybe, it's because of the first line in the 'Routines' code: If vbNo = MsgBox("Do you want to update?", vbYesNo, "Update") Then Exit Function End If

I'll make another subroutine without the MsgBox.

I've been able to reproduce this behaviour. It happens when the focus has to shift to the called database, but the user sets the focus ([ALT]+[TAB]) on the first database. The 'solution' was to educate the user.


This is an intermittent error. As this is production code that will be run only once a month, it's extremely difficult to reproduce, and I can't give you the exact text and number at this time. It is the second month this happened.

I suspect this may occur when someone is working with this or the other database.

The dataflow is to update all 'projects' once a month in one database and then make this information available in the other database.

Maybe, it's because of the first line in the 'Routines' code: If vbNo = MsgBox("Do you want to update?", vbYesNo, "Update") Then Exit Function End If

I'll make another subroutine without the MsgBox.


I've tried this in our development database and it works. This doesn't mean anything as the other code also workes fine in development.

Was it helpful?

Solution 3

I've been able to reproduce the error in 'development'.

"This action cannot be completed because the other application is busy. Choose 'Switch To' to activate ...."

I really can't see the rest of the message, as it is blinking very fast. I guess this error is due to 'switching' between the two databases. I hope that, by educating the user, this will stop.

Philippe, your answer is, of course, correct. I'd have chosen that path if I hadn't developed the 'routine' beforehand.

"I've been able to reproduce this behaviour. It happens when the focus has to shift to the called database, but the user sets the focus ([ALT]+[TAB]) on the first database. The 'solution' was to educate the user." As it is impossible to prevent the user to switch application in Windows, I'd like to close the subject.

OTHER TIPS

I guess this error message is linked to the state of one of your databases. You are using here Jet connections and Access objects, and you might not be able, for multiple reasons (multi-user environment, unability to delete LDB Lock file, etc), to properly close your active database and open another one. So, according to me, the solution is to forget the Jet engine and to use another connexion to update the data in the "other" database.

When you say "The dataflow is to update all 'projects' once a month in one database and then make this information available in the other database", I assume that the role of your "Routine" is to update some data, either via SQL instructions or equivalent recordset updates.

Why don't you try to make the corresponding updates by opening a connexion to your other database and (1) send the corresponding SQL instructions or (2) opening recordset and making requested updates?

One idea would be for example:

Dim cn as ADODB.connexion, 
    qr as string, 
    rs as ADODB.recordset

'qr can be "Update Table_Blablabla Set ... Where ...
'rs can be "SELECT * From Table_Blablabla INNER JOIN Table_Blobloblo  

set cn = New ADODB.connexion
cn.open

You can here send any SQL instruction (with command object and execute method) 
or open and update any recordset linked to your other database, then

cn.close

This can also be done via an ODBC connexion (and DAO.recordsets), so you can choose your favorite objects.

If you would like another means of running the function, try the following:

Dim obj As New Access.Application
obj.OpenCurrentDatabase (CurrentProject.Path & "\Working.mdb")

obj.DoCmd.RunMacro "MyMacro"
obj.CloseCurrentDatabase
Set obj = Nothing

Where 'MyMacro' has an action of 'RunCode' with the Function name you would prefer to execute in Working.mdb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top