Open an access database from excel

LDJB

New Member
Joined
Sep 28, 2006
Messages
21
I am trying to open a database using excel VBA but the code I have below simply opens and closes the database. anybody know what I need to add to keep the database open?

Sub OpenAccess()

Dim LPath As String

LPath = "C:\Directory\Filename.mdb"

Set oApp = CreateObject("Access.Application")
oApp.Visible = True

oApp.OpenCurrentDatabase LPath

End Sub

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi LDJB, welcome to the Board!

Just checking... do you need to open the database so that you can use forms etc, or do you just need to retrieve or push data?

If it's a case of data access, you don't actually need to open the database at all: you just open a connection to the database. If you provide a bit more info on what you need to achieve as the end result, we can help you get there.

Denis
 
Upvote 0
Hi,

Thanks for the reply. Basically all I need to do is keep the database open after the code has run. The database will automatically open a form on startup which I will then need to change dates on the form and run reports. When I step through the code the database opens but then at end sub the database closes, all i need is code to keep it open!!

thanks
 
Upvote 0
Consider using Shell. Here is a sample I picked off another forum -- you could adapt it:

Code:
Sub Launch_Access()
   Dim dTaskID As Double, path As String, file As String

   path = "The full path to the Access.exe"
   file = "The full path to the database"
   dTaskID = Shell(path + " " + file, vbNormalFocus)

End Sub

Denis
 
Upvote 0

Forum statistics

Threads
1,214,986
Messages
6,122,611
Members
449,090
Latest member
vivek chauhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top