使用Form.Requery时运行时错误3246

时间:2018-06-07 00:14:35

标签: database vba ms-access

我目前正在开发一个作为排队系统的访问数据库,该系统的表单显示客户端的号码被调用以及在哪个计数器上。为了只有一台计算机显示表单,同时需要四台计算机才能使用数据库,我提出了一个名为“CommandRequest”的子表单,其中包含文本框命令,请求和启用。它的定时器间隔为2500.在On Timer事件中,我做了以下操作:

Private Sub Form_Timer()
Dim rst As Recordset
'Dim read As Object
'Set read = CreateObject("sapi.spvoice")
Set rst = CurrentDb.OpenRecordset(Name:="CR_List", Type:=RecordsetTypeEnum.dbOpenDynaset)

If command = 1 Then
Dim currdigitD, currletterposD, currnumD, currletterD, currfullD, currlenD, extrazerosD
DoCmd.SetWarnings False

currdigitD = DLookup("[current_digitD]", "current_digitD")
currletterposD = DLookup("[letter_positionD]", "current_letterD")
currnumD = DLookup("[current_numberD]", "current_numberD")
currletterD = DLookup("[current_letterD]", "current_letterD")

If currnumD < 9999 Then
' increase currnum
    DoCmd.OpenQuery "increase_current_numberD"

    currnumD = DLookup("[current_numberD]", "current_numberD")


Else
' set currnum back to 0
' increase digit
' increase letter

    DoCmd.OpenQuery "increase_current_numberD"
    currnumD = DLookup("[current_numberD]", "current_numberD")

    DoCmd.OpenQuery "increase_digitD"
    currdigitD = DLookup("[current_digitD]", "current_digitD")
    If currdigitD = 0 Then
        DoCmd.OpenQuery "increase letterD"
        DoCmd.OpenQuery "update letterD"
        currletterD = DLookup("[current_letterD]", "current_letterD")
    End If

End If

DoCmd.SetWarnings True

' field on form = current letter & current digit & current number

currlenD = Len(Trim(Str(currnumD)))
If currlenD = 3 Then
    extrazerosD = "0"

End If

currfullD = currletterD & Trim(Str(currdigitD)) & extrazerosD & Trim(Str(currnumD))
Forms![FrmPassport]![CURNUM] = currfullD

If Request = 2 Then
    Forms![FrmPassport]![CURCOUNTER] = 2
    Forms![FrmPassport]![Counter2Num] = Forms![FrmPassport]![CURNUM]
    'read.speak "Information Lane. Number," & Forms![FrmPassport]![CURNUM] & "please proceed to counter 2."
    DoCmd.RunCommand acCmdDeleteRecord
    Form.Refresh
    Me.enable = 1

ElseIf Request = 3 Then
    Forms![FrmPassport]![CURCOUNTER] = 3
    Forms![FrmPassport]![Counter3num] = Forms![FrmPassport]![CURNUM]
    read.speak "Information Lane. Number," & Forms![FrmPassport]![CURNUM] & "please proceed to counter 3."
    DoCmd.RunCommand acCmdDeleteRecord
    Form.Refresh
    Me.enable = 0

ElseIf Request = 5 Then
    Forms![FrmPassport]![CURCOUNTER] = 5
    Forms![FrmPassport]![Counter5Num] = Forms![FrmPassport]![CURNUM]
    read.speak "Information Lane. Number," & Forms![FrmPassport]![CURNUM] & "please proceed to counter 5."
    DoCmd.RunCommand acCmdDeleteRecord
    Form.Refresh
    Me.enable = 0

Else

End If




ElseIf command = 4 Then
If enable = 1 Then
    DoCmd.GoToRecord , "", acNext

Else
    If (Not (rst.EOF) And Not (rst.BOF)) Then
        Form.Requery
        Form.Refresh
    End If
    Me.enable = 1
End If

Else
 Me.enable = 0
 DoCmd.GoToRecord , "", acFirst
 Form.Refresh

End If


End Sub

上面的代码可以在打开表单之前添加2条或更多条记录,但是,在代码运行时添加新记录时,我得到“错误3246在事务中不支持操作”,当我尝试调试时,它突出显示`Form.Requery'。有解决方案吗?

0 个答案:

没有答案