tags:

views:

3533

answers:

7

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.

+1  A: 

I ran a test using your exact code above. In a second database I created a single module with the following method:


public Sub Routine()
     MsgBox "Inside the routine"
End Sub

and it worked perfectly fine, exactly as expected.

Your problem is related to what "Routine" is trying to do - you will need to post that code to get an answer to your question.

Remi Despres-Smyth
A: 

I've never seen Access give that particular error message. I've seen "you don't have permission to open the database" and "Access can't set focus on" an object, but not the error message you state. Could you please post the error number and the exact error message? I suspect, as Remi does, that the error is in the code in your routine in the other db, so you'll probably need to post that, too.

Chris OC
A: 

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.

GUI Junkie
Since it's impossible to reproduce in a dev environment, looks like you'll have to wait until next month to get the error code and message. I agree it could be that someone without necessary Windows permissions has blocked the db from being opened. I don't think your msgbox code is causing it.
Chris OC
A: 

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.

GUI Junkie
Again, the problem is not in the code that calls your other database, it's in the other database. At this point you don't know why you're getting an error - you need to be closer to the source for someone to help. I'd start by figuring out which line of code and/or routine is raising the error.
Remi Despres-Smyth
+1  A: 

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.

Philippe Grondier
A: 

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

Curtis Inderwiesche
+1  A: 

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.

GUI Junkie