由于是用函数来调用Access(独占方式)
Public Function ExecuteSQL(ByVal strSQL As String, strLockType As String) As ADODB.Recordset
如此会造成无法关闭Access,除非关闭程序。
而压缩数据库需要关闭Access,
请问如何关闭Access后再压缩Access?
作者: t小宝 时间: 2010-8-31 22:40
不是很明白你的意思
系统选项中可以设置退出时压缩作者: chenwm1973 时间: 2010-9-1 07:25
是用VB编程调用操作Access
在整个程序运行期间,Access一直打开
现在问题是不知如何在运行中关闭。
函数代码如下
Public Function ExecuteSQL(ByVal strSQL As String, strLockType As String) As ADODB.Recordset
Dim rs As New ADODB.Recordset
Dim DBcnn As New ADODB.Connection
On Error GoTo ExecuteSQL_Error
Set DBcnn = New ADODB.Connection
DBcnn.ConnectionString = "uid=admin;pwd=123;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & App.Path & "\HR_data_Phone.mdb "
DBcnn.Open
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
If UCase(strLockType) = "W" Then '写数据"w"或"W"
rs.Open Trim$(strSQL), DBcnn, adOpenStatic, adLockPessimistic
Else '只读数据"r"或"R"
rs.Open Trim$(strSQL), DBcnn, adOpenStatic, adLockReadOnly
End If
Set ExecuteSQL = rs
ExecuteSQL_Exit:
Set rs = Nothing
Set DBcnn = Nothing
Exit Function
ExecuteSQL_Error:
If Err.Number <> 0 Then
MsgBox "错误信息:" & Err.Description , vbCritical, "错误"
End If
Resume ExecuteSQL_Exit
End Function 作者: koutx 时间: 2010-9-1 15:51 本帖最后由 koutx 于 2010-9-1 15:55 编辑