ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems opening Access database from Excel VBA (https://www.excelbanter.com/excel-programming/300142-problems-opening-access-database-excel-vba.html)

Jan[_11_]

Problems opening Access database from Excel VBA
 
I try to open an Access database from Excel using the following code:

Sub OpenDatabase()

strdb = "c:\demo.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strdb
appAccess.DoCmd.OpenForm "frmsysteminformation"
Set appAccess = Nothing

End Sub

This shows the form OK, but not the Access window. When I close the form it
disappears, but leaves theAccess application running in Background.

How can I open a databae in the database window and gain access, not only to
the form, but to the full Access, that is Databasewindow and all?

Jan



AA2e72E[_2_]

Problems opening Access database from Excel VBA
 
You need to set the visible property to true
appAccess.visible = true
before you set it to nothing.

Jan Karel Pieterse

Problems opening Access database from Excel VBA
 
Hi Jan,

Change your code to:

Sub OpenDatabase()

strdb = "c:\demo.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.Visible=True
appAccess.OpenCurrentDatabase strdb
appAccess.DoCmd.OpenForm "frmsysteminformation"
Set appAccess = Nothing

End Sub

Sub OpenDatabase()

strdb = "c:\demo.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strdb
appAccess.DoCmd.OpenForm "frmsysteminformation"
Set appAccess = Nothing

End Sub

This shows the form OK, but not the Access window. When I close the form it
disappears, but leaves theAccess application running in Background.

How can I open a databae in the database window and gain access, not only to
the form, but to the full Access, that is Databasewindow and all?


Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com


Jan[_11_]

Problems opening Access database from Excel VBA
 
Thank you both. That did the trick :-). An couple off additional question:
What if I do not want to open a form, but just want to display the
database window.
If i remove the OpenForm line, Access is started all right, but nothing is
shown.

And can I test if the database is already open before opening it?

Jan

"Jan Karel Pieterse" wrote in message
...
Hi Jan,

Change your code to:

Sub OpenDatabase()

strdb = "c:\demo.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.Visible=True
appAccess.OpenCurrentDatabase strdb
appAccess.DoCmd.OpenForm "frmsysteminformation"
Set appAccess = Nothing

End Sub

Sub OpenDatabase()

strdb = "c:\demo.mdb"
Set appAccess = CreateObject("Access.Application")
appAccess.OpenCurrentDatabase strdb
appAccess.DoCmd.OpenForm "frmsysteminformation"
Set appAccess = Nothing

End Sub

This shows the form OK, but not the Access window. When I close the form

it
disappears, but leaves theAccess application running in Background.

How can I open a databae in the database window and gain access, not

only to
the form, but to the full Access, that is Databasewindow and all?


Regards,

Jan Karel Pieterse
Excel MVP
www.jkp-ads.com





All times are GMT +1. The time now is 03:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com