Error de variable no definido en el acceso
-
23-12-2019 - |
Pregunta
Estoy teniendo problemas para compilar esto, sigue dando un error de variable indefinido durante la compilación en 'incdntno.value'.Intenté dimiturar Incdntno como entero, pero luego se estaba invirtiendo calificador inválido.Tengo un código similar que funciona (vea el segundo bloque de código).No necesitaba mucho de lo que iba en la parte del código de trabajo, así que lo quité.¿Estaría tan agradecido si alguien puede señalar dónde me voy mal en el primer bloque de código?Gracias, mucho
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
Código que funciona:
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
Solución
Esto suena como lo que sucede si duplica el código de evento.Mire de cerca sus nombres de control y asegúrese de que coincidan.Además, querrá asegurarse de que aparezca [Procedimiento de evento] en las propiedades del evento.Ese enlace puede no aparecer automáticamente si cambia los nombres de control.