excel vba to open a new access file

Rayne
Rayne used Ask the Experts™
on
Hello,


I was wondering how i can do this in vba....i want a button in excel that opens a new instance of access and set a object reference to that newly opened DB like this
set myNewDB = .....

thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
Dim db As DAO.Database, accFilePath As String

accFilePath = "c:\folder\myAccess.accdb"

set db=opendatabase(accFilePath)



'what do you want do after that?
Please try this.

Sub test2()


Dim strPath As String

Dim db As Object
Application.DisplayAlerts = False

strPath = "C:\USERS\yourname\mydatabase"
Set db = CreateObject("Access.Application")
Call db.NewCurrentDatabase(strPath)
db.Application.Visible = True
Application.DisplayAlerts = True
End Sub

Open in new window

Author

Commented:
thank you
You welcome

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial