I'm trying to get a list of all tables from an Access 2007 ACCDB format database using Excel VBA.
I have followed this post:
How can I get table names from an MS Access Database?
Using:
SELECT MSysObjects.Name AS table_name
FROM MSysObjects
WHERE
(((Left([Name],1))<>"~")
AND ((Left([Name],4))<>"MSys")
AND ((MSysObjects.Type) In (1,4,6)))
order by MSysObjects.Name
but I'm getting this error.
Record cannot be read; no read permission on 'MSysObjects'
I want to be able to get the table names only using a SQL statement and not the OpenSchema
method.
I think the problem is with Access. I'm not sure.
Does anybody have any idea?
Here's what worked for me, since this is the first SO question that comes up for this:
this is an MDB file. Don't know about others. I understand this is not what the question asked for. However, StackOverflow questions/answers are also used by many other people arriving here via google, as I did, and I'm using MDB. I hope this answer is of use to someone else.
Open MS Access GUI. Didn't figure out how to do this without it, sorry, though it's likely possible.
Go to Tools...Options...
Click "View" tab
select "Hidden objects", "System objects"
close tab
Go to Tools...Security.. User and Group permissions
Select all the table names including MSysObjects
click all the "permissions" checkboxes so they set up as "checked" for all entries
apply/OK as needed
Since your db is ACCDB format, you will be working as user Admin. You can confirm that point in the Immediate window. (Go there with Ctrl+g)
? CurrentUser()
Admin
Since Admin doesn't have read (SELECT
) permission on MSysObjects
, execute a DDL statement to give Admin that permission.
strDdl = "GRANT SELECT ON MSysObjects TO Admin;"
CurrentProject.Connection.Execute strDdl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With