Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open Access DB file from Excel (VBA)

Status
Not open for further replies.

TeeBruin

Technical User
Dec 16, 2001
9
US
I'm trying to get some code to open an Access database file from within Excel. I don't need to open a specific table or form, I just need to open the database and the user can decide what they want to do from there.

I've tried the following code, but I'm not having any luck. I have just been trying stuff, because I'm not real proficient with VBA.

Dim AccApp As New Access.Application
Dim strDB As String
strDB = "database filename"
AccApp.OpenCurrentDatabase (strDB)

Thanks in advance for any help.
 
There is a forum on tek tips for VBA questions. I am afraid I can't help you but perhaps try posting your question there. Good luck.
 

Hello there
This may be of use just follow the steps below

1:In the VBA window of excel - At the Very top Copy the 2
lines below


Option Explicit
Dim AccApp As New Access.Application


2:The code snippet below I have just tried from excel and
it works
BUT you will need to replace paths etc if the ones above are only examples
Otherwise copy as is directly into you module & happy coding


Sub openAccessMDB()
Dim a As String

Dim strDB As String
ChDir "C:\" 'Change to appropriate Drive
Set AccApp = CreateObject("Access.Application")
strDB = "database filename" ' full path including.mdb


a = Dir(strDB)
if a = "" then
msgbox "database not found"
exit sub
else
AccApp.OpenCurrentDatabase strDB
AccApp.Visible = True 'Access show yourself
end if
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top