compact the user-level security

G

Guest

Hi,

I found the below code for compact the user level security.

When I call like this:
Call CompactAndRepairDB("C:\db1.mdb", "C:\compacttemp.mdb",
"C:\Secured.mdb", "Admin", "")

It give out the error message.

If I change to
Call CompactAndRepairDB("C:\db1.mdb", "C:\compacttemp.mdb",
"C:\Secured.mdb", "John", "johnpass")

Then the error message is:
Run-time error '-214727843 (80040e4d)'

Cannot start your application. The workgroup information file is missing or
opened exclusively by another user.

'************************************************* **************
' CompactAndRepairDB (FUNCTION)
'
' PARAMETERS:
' sSource - Path to source database
' sDestination - Path for destination database
' sSecurity - Path to Jet system database if there is
' one
' sUser - The username if user level security is
' turned on
' sPassword - The password if user level security is
' turned on
' lDestinationVersion - If the destination database should
' not be in the latest version of Jet
' then use this variable to specify
' the version required; 1 = Jet 1.0,
' 2 = Jet 1.1, 3 = Jet 2.x,
' 4 = Jet 3.x, 5 = Jet 4.x etc
'
' RETURN VALUE:
' Boolean - Success indicator
'
' DESCRIPTION:
' This function uses the Microsoft Jet and Replication Objects
' Library (part of ADO) to compact and repair a Microsoft Access
' database. A project reference is required to the Microsoft Jet
' and Replication Objects Library.
'
' You may want to add error handling to this procedure, or to
' the function that calls it as the compact and repair may fail,
' for instance, if exclusive access cannot be gained to the
' source database.
'************************************************* **************
Public Function CompactAndRepairDB(sSource As String, _
sDestination As String, _
Optional sSecurity As String, _
Optional sUser As String = "Admin", _
Optional sPassword As String, _
Optional lDestinationVersion As Long) As Boolean

Dim sCompactPart1 As String
Dim sCompactPart2 As String
Dim oJet As JRO.JetEngine

' 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 OLEDBystem 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
End Function


-------------------------------------------

I have a question.

How can I call the function using Admin without password?
How can I call the function using the username with password?

I want to know both of them.
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top