Opend Database from Excel via code

Boris7265

Board Regular
Joined
Apr 6, 2011
Messages
68
Hello to all of you .

I have used the below code but the database just opens and closes??

Code:

Sub OpenAccess() Dim LPath As String Dim LCategoryID As Long LPath = "C:\Directory\Filename.mdb" Set oApp = CreateObject("Access.Application") oApp.Visible = True oApp.OpenCurrentDatabase LPath End Sub</PRE>
Please anybody know how to keep it open?

Thank you,

The Best Regards,

BorisGomel
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hmm. That's weird.
It shouldn't close??

See if you have ignore all other applications on...You might have to google it.

Do you have any other macros?
 
Upvote 0
Code:
Sub OpenAccess() 
 
  Dim LPath As String 
  Dim LCategoryID As Long 
 
  LPath = "C:\temp\scratch_database1.mdb" 
  Set oApp = CreateObject("Access.Application") 
  oApp.Visible = True 
  oApp.OpenCurrentDatabase LPath 
 
End Sub

Where is oApp declared? If it isn't declared correctly, when the procedure ends, oApp is destroyed and the database closes as a result. Place a breakpoint at the End Sub statement and verify this for yourself.

If you're not going to access your database using the references you're creating, why not simply go:-
Code:
Shell "msaccess C:\temp\scratch_database1.mdb"

If you're going to use those references outside the procedure, oApp needs to be declared outside it.

PS. Please post code between code tags - the # icon in the advanced editor toolbar - as it makes it easier for potential responders to read and understand your code, and this encourages more replies.
 
Upvote 0
Thank you all of you , specially Ruddles .

I didn't declare oApp (Opps).I did declare it as an Object outside the procudere and now it is working fine .

Thank you very much .

The Best Regards,

BorisGomel
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

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