Access中未定义的变量错误

时间:2014-02-27 16:55:04

标签: sql compiler-errors access-vba

我无法编译它,它在'Incdntno.Value'编译期间一直给出一个未定义的变量错误。我试图将Incdntno Dim作为整数,但随后获得了无效的限定符。我有一个类似的代码(见第二个代码块)。我不需要工作代码部分的大量内容,所以我删除了它。如果有人能指出我在第一个代码块中出错的地方,我将非常感激?非常感谢你

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

1 个答案:

答案 0 :(得分:2)

这听起来像复制事件代码时会发生什么。仔细查看控件名称并确保它们匹配。此外,您还需要确保事件属性中出现[事件过程]。如果更改控件名称,该链接可能不会自动显示。