Helpfile's "OpenCurrentDatabase" method doesn't work consistently

Noel

Registered User.
Local time
Today, 08:00
Joined
Apr 13, 2007
Messages
61
Any thoughts would be greatly appreciated.

The Helpfile example sub display form() below was run and returned the northwind.mdb form "orders", but when I plugged in my own variables, nothing seems to appear.

Sub DisplayForm()

'Dim appAccess As Access.Application ' dimensioned in the head declarations

Dim strDB as String

' Initialize string to database path.
Const strConPathToSamples = "C:\Program " _
& "Files\Microsoft Office\Office11\Samples\"

strDB = strConPathToSamples & "Northwind.mdb"
' Create new instance of Microsoft Access.
Set appAccess = _
CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strDB
' Open Orders form.
appAccess.DoCmd.OpenForm "Orders"
End Sub

================I ran the helpfile code above and it gives you the access database window (northwind.mdb) and the form "Orders" as expected
================Same code below, but with my variables does not return the new access database window (remote.mdb) nor the form "frmRemote".


Function triggerit()

'Dim appAccess As Access.Application ' dimensioned in the head declarations

Dim strDB As String

strDB = "C:\Documents and Settings\Central\Desktop\remote.mdb"
' Create new instance of Microsoft Access.
Set appAccess = CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strDB, True
' Open Orders form.
appAccess.DoCmd.OpenForm "frmRemote"

End Function

when I call function triggerit (), i.e. "call triggerit" from the intermediate window, it looks like it runs but I don't get the new access window or the form.

When I try to run triggerit again, I get an error message that makes sense "Microsoft Access can't open the database because it is missing, or opened exclusively by another user"...but I don't see the access window or the form (not even in the windows task manager "applications" tab via the ctl+alt+delete.

I try to delete or move the remote.mdb and I get a similar error "it is being used by another person or program"...but the mdb doesn't appear visible.

I've since gotten the opencurrentdatabase method to work opening a different mdb, but I've since also tried the opencurrentdatabase method to open another mdb, but it didn't work.

Any thoughts would be much appreciated.


Thanks.

Noel
 
First of all, you should use appAccess.Visible = True right after creating it.

Next, you should probably test to see if appAccess has a state of open since you have it declared in the general declarations and you won't be able to create another instance of it until it has been destroyed (appAccess=Nothing)
 
thanks

Thanks Bob

It'd be nice if the help file mentioned the .visible argument.

How do you check the state of appAccess?

Thanks again.

Noel
 
Not sure about checking if it's open already. But, at least with 2003, my test had it opening the database again, replacing the current open one, when I kept clicking the button. So, you may not need it as long as you set it's visible = true.
 

Users who are viewing this thread

Back
Top Bottom