我在编译该文件时遇到了麻烦,在“Incdntno.Value”的编译过程中,它始终给出 undefined variable 错误。我尝试将Dim Incdntno设置为Integer,但随后获得了无效的限定词。我有一个类似的代码可以工作(请参阅第二个代码块)。我不需要工作代码部分的大量内容,因此将其删除。如果有人可以指出我在第一个代码块中哪里出了问题,我将非常感激。非常感谢你
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
最佳答案
这听起来像如果您重复事件代码会发生什么。请仔细查看您的控件名称,并确保它们匹配。另外,您还要确保[事件过程]出现在事件属性中。如果您更改控件名称,该链接可能不会自动出现。
关于sql - 'Incdntno.Value'的 undefined variable ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22075109/