Hi everyone,
I am new to VB/VBA so kindly bear with me if my question sounds naive.
I am trying to connect to a Access 2002 Database from an Excel 2002 worksheet macro. I think I am able to open the database fine, but when I try to create a QueryDef object in order to run some queries, I keep getting a Runtime error. It says "Runtime Error: 3027 Cannot update. Database or Object is read-only".
Here is the piece of code that leads to the error.
Now I have 2 questions. One, how do you check to see if you have a successful connection to the Database. Second, why am I getting this error and what can I do to overcome it.
Thanks a lot in advance for your help.
I am new to VB/VBA so kindly bear with me if my question sounds naive.
I am trying to connect to a Access 2002 Database from an Excel 2002 worksheet macro. I think I am able to open the database fine, but when I try to create a QueryDef object in order to run some queries, I keep getting a Runtime error. It says "Runtime Error: 3027 Cannot update. Database or Object is read-only".
Here is the piece of code that leads to the error.
Code:
Sub loadDB()
Dim db As Database
Dim recSet As Recordset
Dim query As String, qDef As QueryDef
Set db = DBEngine.Workspaces(0).OpenDatabase( _
"C:\MyApps\Access\DBConnect\Company.mdb", False, True)
MsgBox "Database opened successfully..."
query = "SELECT * from tblCompany where City = 'London'"
Set qDef = db.CreateQueryDef("shopNameQuery", query)
Set recSet = qDef.OpenRecordset(dbOpenForwardOnly, , dbReadOnly)
Do While Not recSet.EOF
Debug.Print recSet.Fields("Company Name")
Loop
db.Close
End Sub
Thanks a lot in advance for your help.