WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADO DAO
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

ADOX Grant Permissions


Referenced:
http://msdn.microsoft.com/library/en-us/ado270/htm/admscgrantingpermissionsexample.asp?frame=true
#DefineFunction GrantPermissions(my_mdb, user, table)
    retval = 0
    ;Error  handling
    IntControl(73,1,0,0,0)

    cnn = ObjectCreate("ADODB.Connection")
    cat = ObjectCreate("ADOX.Catalog")
    ;Get handle to constants
    oconst = ObjectConstantsGet(cat)

    ;Opens a connection to the database using the Microsoft Jet 4.0 provider
    cConn = StrCat("Provider=MicroSoft.Jet.OLEDB.4.0; Data Source=",my_mdb,";jet oledb:system database='C:\PROGRA~1\COMMON~1\System\SYSTEM.MDW'")

    cnn.Open(cConn)
    cat.ActiveConnection = cnn

    ;Retrieve original permissions
    ;lngPerm = cat.Users(user).GetPermissions(table, oconst.adPermObjTable)
    ;Message( "Original permissions: " , lngPerm)

    ; Revoke all permissions
    cat.Users(user).SetPermissions(table, oconst.adPermObjTable, oconst.adAccessRevoke, oconst.adRightFull)
    ;Display permissions
    ;Message("Revoked permissions: " , cat.Users(user).GetPermissions(table, oconst.adPermObjTable))

    ; Give the user full rights on the TestTable object
    cat.Users(user).SetPermissions(table, oconst.adPermObjTable, oconst.adAccessSet, oconst.adRightFull)
    ; Display permissions
    ;Message("Full permissions: " , cat.Users(user).GetPermissions(table, oconst.adPermObjTable))

    ;Restore original permissions
    ;cat.Users(user).SetPermissions(table, oconst.adPermObjTable, oconst.adAccessSet, lngPerm)
    ; Display permissions
    ;Message( "Final permissions: " , cat.Users(user).GetPermissions(table, oconst.adPermObjTable))

    ;Clean up
    cnn.Close
    cat = 0
    cnn = 0
    retval = 1
    Return(retval)

:WBERRORHANDLER
   ;GrantPermissionsError:
   cat = 0
   If cnn
      If cnn.State = oconst.adStateOpen Then cnn.Close
   End If
   cnn = 0
   Message( "Error granting permissions",StrCat(wberrorhandlerline,@CRLF,wberrortextstring,@CRLF,wberroradditionalinfo))
   Return(retval)

#EndFunction


;***************************************************************************
;**
;** Purpose: Gives User Full permissions to the Access Table
;**
;** Author: Deana Falk
;**
;** Revisions:
;**    December 13th 2005
;**    Designed and tested on Windows XP SP2, using WinBatch 2005G and
;**    MS Access 2000.
;***************************************************************************

; Change to fit your needs
table = "TestTable"
my_mdb = 'C:\Temp\Data\Test.mdb'
user = 'Deana'



ret = GrantPermissions(my_mdb, user, table)
If ret == 0
   Message("Notice","There was a problem granting permissions")
   Exit
EndIf
Message("","Done")

Article ID:   W17107
File Created: 2007:07:03:14:28:20
Last Updated: 2007:07:03:14:28:20