PDA

View Full Version : Solved: VB6 - set 'read' property for MS Access table?



andrew93
09-20-2006, 07:36 PM
Hi

I have an application in VB6 that links to a local Access database. I need to change the 'Read Data' property for one of the tables within the database and cannot work out how to do this using VB6.

I can do this manually like so : within Access, click Tools > Security > User and Group Permissions > select the table > tick or untick the 'Read Data' property. However, I need to be able to do this from within the VB6 application.

Does anyone have any suggestions how to do this using VB?

I'm currently using DAO to connect to the database but if I have to change that to ADO to achieve this, then that would be ok.

TIA, Andrew

Late edit : I also posted this same question on another forum here : http://www.mrexcel.com/board2/viewtopic.php?p=1122748

and for clarification purposes, I have read/write access to the database - I want to get 'Read' access to one of the hidden Access tables (ie MSysObjects).

andrew93
09-20-2006, 11:08 PM
Ok - I think I have figured it out thanks to Denis (aka SydneyGeek) at the other forum. The following code performs the trick :

Sub GrantPermissions()

Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog

cnn.Provider = "Microsoft.Jet.OLEDB.4.0"

cnn.Properties("Jet OLEDB:Database Password") = strPass

cnn.Open "data source=" & dbFileName & _
"; jet oledb:system database=C:\Documents and Settings\Andrew\Application Data\Microsoft\Access\system.mdw", _
UserID:="Admin"

Set cat.ActiveConnection = cnn

'Give the Admin user Read rights on the MSysObjects object

'Just to help find the groups
Dim x As Integer
Dim xUserCount As Integer
xUserCount = cat.Users.Count
Debug.Print xUserCount
For x = 0 To xUserCount - 1
Debug.Print cat.Users(x)
Next

cat.Users("Admin").SetPermissions "MSysObjects", adPermObjTable, adAccessGrant, adRightRead

End Sub
but it gives me occasional problems - but only with databases that have passwords.

Thanks for looking!
Andrew