访问中未定义的变量错误
-
23-12-2019 - |
题
我遇到了难以编译,它在'Incdntno.Value'期间,它一直在编译期间给出未定义的变量错误。我尝试将Incdntno暗中为整数,但随后越无效。我有一个类似的代码(参见第二代码块)。我不需要很多工作代码部分,所以我删除了它。如果有人能指出第一个代码块的位置,我会非常感激?谢谢,非常
Private Sub Incdntno_AfterUpdate()
Dim conn As ADODB.Connection
Dim sSQL As String
Set conn = CurrentProject.Connection
If IsNull([Incdntno]) Then
Me.Dirty = False
End If
Dim Incident As String
Incident = Incdntno.Value
sSQL = "INSERT INTO tblFieldIncident_Complaint_InspHist ( Incdntno, InspectID, Dt_Inspect ) SELECT " & [Incdntno] & ", " & [InspectID] & ", " & [InspDate] & " FROM tblInspect WHERE Incdntno='" & Incident & "';"
conn.Execute sSQL
'Me.Requery
frmInspectItemsSub.Requery
ProcExit:
Exit Sub
End Sub
.
工作的代码:
Private Sub InspectType_AfterUpdate()
Dim conn As ADODB.Connection
Dim sSQL As String
Dim wYesNo As Integer
On Error GoTo ProcErr
If Not mbNewRecord Then
wYesNo = MsgBox("Changing the inspection type will erase the current entries and insert items specific to the new inspection. Proceed?", vbYesNo, "Inspection item update")
If wYesNo <> vbYes Then GoTo ProcExit
End If
Set conn = CurrentProject.Connection
If Not mbNewRecord Then
conn.Execute "DELETE FROM tblInspectItems WHERE InspectID=" & InspectID
End If
If IsNull([InspectID]) Then
Me.Dirty = False
End If
Dim inspType As String
inspType = InspectType.Value
sSQL = "INSERT INTO tblInspectItems ( ItemID, InspectID ) SELECT ItemID, " & [InspectID] & " FROM tblRefInspectItemCodes WHERE InspectType='" & inspType & "';"
conn.Execute sSQL
'Me.Requery
frmInspectItemsSub.Requery
ProcExit:
Exit Sub
ProcErr:
ErrMsg ("frmInspect.InspectType_AfterUpdate")
Resume ProcExit
End Sub
. 解决方案
这听起来像是在复制事件代码时会发生什么。仔细查看您的控制名称,并确保它们匹配。此外,您需要确保在事件属性中出现[事件过程]。如果更改控件名称,则该链接可能不会自动出现。
不隶属于 StackOverflow