VBA:桌面由管理员锁定

时间:2014-05-21 08:56:30

标签: sql vba ms-access-2010

我有一个问题,我在Access数据库中有一个函数,它将记录插入表中。 问题是代码失败了,因为它声称管理员已锁定数据库以进行访问,而我无法写入表。我检查了MS Access设置并删除了独占访问选项。我已经压缩并修复它并逐步完成每条线路。有时候它会起作用,大部分时间都没有,而且在锁定时不一致

即使它位于网络驱动器上,我也是唯一使用它的人。任何人都可以看到为什么会这样。有时候它会起作用,有时它不起作用,我现在已经看了一个多月了,不能看出问题是什么

'**********************************************************************************
'FUNCTION NAME:     CreateErrorTable
'AUTHOR:            [JS]
'DEPENDANCIES:      NA
'FUNCTIONALITY:     Takes in a selection of variables and appends them to an error table
'                   Clears the Table on the first run of the function based on the flag intEmptyTable
'MODIFICATIONS:     None
'**********************************************************************************
Public Function CreateErrorTable(strAWB As Variant, strOrigCtry As Variant,  strDestCtry As Variant, rlTrueValue As Variant, strTrueCurr As Variant, intEmptyTable As Boolean) As Boolean

On Error GoTo ErrorHandler
Dim dbs As Database
Set dbs = OpenDatabase("O:\NetworkDrive\Database1.accdb")
CreateErrorTable = True

If intEmptyTable = True Then
    DelStrSQL = "DELETE [X-ERROR_TABLE].* FROM [X-ERROR_TABLE];"
    dbs.Execute DelStrSQL
End If

StrSQL = "INSERT INTO [X-ERROR_TABLE] " _
& "(A,Value,Curr,Ctr,[DCtr]) VALUES " _
& "('" & strA & "'," & rlValue & ",'" & strCurr & "','" & strCtry & "','" & strDCtry & "');"
dbs.Execute StrSQL

ErrorHandler:
    If (Len(Err.Description) > 0) Then
        Debug.Print "CreateErrorTable " & Err.Description
        Debug.Print "CreateErrorTable " & StrSQL
        CreateErrorTable = False
    End If
    GoTo EndFunction

EndFunction:
    dbs.Close

End Function

0 个答案:

没有答案