View Full Version : Open a database using vba
sassora
02-07-2008, 10:07 AM
I keep getting a runtime error: 7866
The debug flags "oApp.OpenCurrentDatabase LPath"
any ideas?
Private Sub CommandButton1_Click()
Dim LPath As String
'Path to Access database
LPath = CurDir & "\QA.mdb"
'Open Access and make visible
Set oApp = CreateObject("Access.Application")
oApp.Visible = True
'Open Access database as defined by LPath variable
oApp.OpenCurrentDatabase LPath
End Sub
rconverse
02-07-2008, 07:36 PM
I keep getting a runtime error: 7866
The debug flags "oApp.OpenCurrentDatabase LPath"
any ideas?
Private Sub CommandButton1_Click()
Dim LPath As String
'Path to Access database
LPath = CurDir & "\QA.mdb"
'Open Access and make visible
Set oApp = CreateObject("Access.Application")
oApp.Visible = True
'Open Access database as defined by LPath variable
oApp.OpenCurrentDatabase LPath
End Sub
I am very new to Excel VB, but I think you might need a with statement.
with oApp
.opencurrentdb LPath
'do stuff
End with
I am assuming that you are going to do something in Access and then pass control back to Excel. This also assumes the rest of your code is correct and that oApp is a public variable as you don't have it dim'd here.
HTH
Roger
RichardSchollar
02-08-2008, 01:54 AM
Hi
Do you actually have a database named "QA.mdb" at the given location?
Richard
Bob Phillips
02-08-2008, 02:24 AM
Also, are you sure CurDir ios pointig where you think it is?
sassora
02-08-2008, 06:27 PM
Yes the QA database is there and the code works if you use a string path for example "C:\Windows" but I want it variable so that the code will work from any folder I choose.
sassora
02-08-2008, 06:32 PM
msgbox(CurDir) gives the correct location but after running it seems to point to My dcuments. I have placed a copy of it in there too but no luck.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.