Toxalot said:
Yes, it is.
So far I've been using ADO for everything. Is there
a way to do it with ADO?
There is no way to do it from ADO.
One problem with the other poster's code is that in order to Compact and
Repair the database (BTW, in Access 2000 and on those two functions are
combined in the CompactDatabase method) the .MDB you are trying to compact
must be closed, with no other users in it. If you are doing it from your FE
this means that all forms that reference the BE must be closed, and no other
users can be in the BE, either. In other words, the form you are calling
CompactDatabase from must not be bound to the BE in any way. If you have
ever checked out various performance-related issues in these NG's, you
probably are using an always open bound form to increase performance to your
BE. Those would need to be closed, also. There is a DLL you can incorporate
in your application (available from Microsoft - search for JetUtils) that
has functions that will tell you if all usres are out of the database, and
if not, which users are still in. Here is a sample code snippet (not
complete) for using MSLDBUSR.DLL:
Declare Function LDBUser_GetUsers Lib "MSLDBUSR.DLL" (lpszUserBuffer() As
String, ByVal lpszFilename As String, ByVal nOptions As Long) As Integer
Declare Function LDBUser_GetError Lib "MSLDBUSR.DLL" (ByVal nErrorNo As
Long) As String
Public Const OptAllLDBUsers = &H1
Public Const OptLDBLoggedUsers = &H2
Public Const OptLDBCorruptUsers = &H4
Public Const OptLDBUserCount = &H8
Public Const OptLDBUserAuthor = &HB0B
Check_Again:
ReDim strUsers(1)
lRet = LDBUser_GetUsers(strUsers, strDBFile, OptLDBLoggedUsers)
If lRet < 0 Then
If lRet <> -2 And lRet <> -14 Then
strError = LDBUser_GetError(lRet)
MsgBox strError, vbExclamation
LogError Me.Name, lRet, strError, "MSLDBUSR.DLL"
Exit Function
End If
ElseIf lRet > 0 Then
'Users are still connected
strMsg = lRet & " users are still connected!" & vbCrLf & _
"Please make sure these users are logged off:" & vbCrLf
For L = LBound(strUsers) To UBound(strUsers)
strMsg = strMsg & strUsers(L) & vbCrLf
Next
strMsg = strMsg & "Click Retry when ready or Cancel to abort."
iResp = MsgBox(strMsg, vbRetryCancel Or vbInformation)
If iResp = vbRetry Then
GoTo Check_Again
Else
Exit Function
End If
End If