OpenCurrentDatabase Issue (1 Viewer)

PeterOC

Registered User.
Local time
Today, 23:46
Joined
Nov 22, 2007
Messages
80
Hi,

I've got a database with a form that contains 3 buttons each one opening a separate database with the following code. 2 of these databases open fine but one flashes up for a second and then disappears:

The code is identical for each.


Code:
Dim accapp As Access.Application
Set accapp = New Access.Application
MsgBox "The Database may open BEHIND the current database. Please minimise this database to view."
accapp.OpenCurrentDatabase ("S:\Waste Management Database\Waste Management Database.accdb"), False
accapp.Visible = True

I'm working on an Access 2010 adp front end linked to sql server 2000.

Any ideas why this might be happening?

Cheers,

Peter
 

vbaInet

AWF VIP
Local time
Today, 15:46
Joined
Jan 22, 2010
Messages
26,374
Was the database being used by other users at the time you tried opening it?
 

PeterOC

Registered User.
Local time
Today, 23:46
Joined
Nov 22, 2007
Messages
80
No, I checked to see if the locking file was open and no, I was the only one using it.

I've got error trapping on and that's not bringing anything up.
 

vbaInet

AWF VIP
Local time
Today, 15:46
Joined
Jan 22, 2010
Messages
26,374
Change False to True and see if it helps.

Also, have you tried manually opening the db to see if it opens? Perhaps there's some AutoExec macro that's causing it to close on open.

The other thing is, after it closes, look in the Task Manager to see if an extra Access process is running.

I would also try accApp.UserControl = True after the Visible line.
 

PeterOC

Registered User.
Local time
Today, 23:46
Joined
Nov 22, 2007
Messages
80
Thanks vbaInet,
the 'accApp.UserControl = True' thing seems to have done the trick. Strange. I don't have this in the code for the other 2 databases and they open fine.

But thanks very much for your help.

Peter
 

vbaInet

AWF VIP
Local time
Today, 15:46
Joined
Jan 22, 2010
Messages
26,374
I've seen that cause hangups before. I must say that the real use of that method is to check whether that instance of Excel was started by a user or by code. It really shouldn't be for giving control to the user, but like I said it seems to work. Even the documentation fot this method clearly states this.

It just goes to show that not all documentation is 100% accurate.

Happy to help!
 

Peter Lee

New member
Local time
Today, 08:46
Joined
Nov 19, 2014
Messages
1
The following code will help totally:

Private Sub Command0_Click()
Dim appAccess As Access.Application
Set appAccess = New Access.Application
appAccess.OpenCurrentDatabase ("D:\Data\My New App.accdb")

appAccess.Visible = True
appAccess.UserControl = True
SendKeys "%{Tab}", True
End Sub
 

Users who are viewing this thread

Top Bottom