|
accessman -> Compact and repair Secured Database (6/1/2006 14:03:12)
|
Hi, I have a db1.mdb with user-level security. The Secured.mdw is security file. Everytime we need to refer Secured.mdw to open the db1.mdb. I created another compact.mdb database for compact and repair the db1.mdb at night time. In the compact.mdb: I create the form and setup the timer to compact the db1.mdb at the night time. I used Public Function CompactAndRepairDB(sSource As String, _ sDestination As String, _ Optional sSecurity As String, _ Optional sUser As String = "Admins", _ Optional sPassword As String, _ Optional lDestinationVersion As Long) As Boolean Dim sCompactPart1 As String Dim sCompactPart2 As String Dim oJet As JRO.JetEngine On Error GoTo Err_compact ' Put together the provider string for the source database sCompactPart1 = "Provider=Microsoft.Jet.OLEDB.4.0" & _ ";Data Source=" & sSource & _ ";User Id=" & sUser & _ ";Password=" & sPassword ' If the database has a user-level security file, add the ' details If sSecurity <> "" Then sCompactPart1 = sCompactPart1 & _ ";Jet OLEDB:System database=" & sSecurity & ";" End If ' Put together the provider string for the destination ' database sCompactPart2 = "Provider=Microsoft.Jet.OLEDB.4.0" & _ ";Data Source=" & sDestination ' The destination database will end up in the latest version ' of jet, unless a specific version has been requested; ' 1 = Jet 1.0, 2 = Jet 1.1, 3 = Jet 2.x, 4 = Jet 3.x, ' 5 = Jet 4.x etc If lDestinationVersion <> 0 Then sCompactPart2 = sCompactPart2 & _ ";Jet OLEDB:Engine Type=" & lDestinationVersion End If ' Compact and repair the database Set oJet = New JRO.JetEngine oJet.CompactDatabase sCompactPart1, sCompactPart2 Set oJet = Nothing CompactAndRepairDB = True Exit_compact: Exit Function Err_compact: MsgBox Err.Description Resume Exit_compact End Function Function CompactWithSecurity() Call CompactAndRepairDB("c:\db1.mdb", "c:\tmp.mdb", "c:\Secured.mdw", "jim") End Function It works, because jim is Adminstrator. But, if Jim is not Adminstrator, then it doesn't work. if jim is assigned "Backup Operators" and "Read-Only Users" permission by Adminstrator. When Jim logged in the Account, Jim can compact the database from clicking option menu (Database Ulities->Compact and Repair Database...). If he used compact.mdb database to compact the db1.mdb with this function Function CompactWithSecurity() Call CompactAndRepairDB("c:\db1.mdb", "c:\tmp.mdb", "c:\Secured.mdw", "jim") End Function Then it doesn't work. How can I fix the function? I want jim to compact the db1.mdb using compact.mdb. But, he is NOT adminstrator. I want to assign limit permission to him to compact the database using compact.mdb file to compact the db1.mdb at the night time. Thanks.
|
|
|
|