Skip to content
Advertisement

Undefined variable at ‘Incdntno.Value’

I am having trouble getting this to compile, it keeps giving an undefined variable error during compile at ‘Incdntno.Value’. I tried to Dim Incdntno as Integer but then was getting Invalid qualifier. I have a similar code that works (see second code block). I didn’t need a lot of what was going in the working code part so I removed it. I would be so grateful if someone can point out where I am going wrong in the first code block? Thank you, very much

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

Code that works:

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

Advertisement

Answer

This sounds like what happens if you duplicate event code. Take a close look at your control names and make sure they match. Also, you’ll want to make sure that [Event Procedure] appears in the event properties. That link may not appear automatically if you change control names.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement