Domanda

Ho problemi a ottenere questo per compilare, continua a dare un errore variabile indefinito durante la compilazione a 'incdntno.value'.Ho provato a oscurare Incdntno come intero ma poi stava ottenendo qualificatori non validi.Ho un codice simile che funziona (vedi il secondo blocco di codice).Non avevo bisogno di molto quello che stava andando nella parte del codice di lavoro, quindi l'ho rimosso.Sarei così grato se qualcuno possa sottolineare dove sto sbagliando nel primo blocco di codice?Grazie, molto

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
.

Codice che funziona:

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
.

È stato utile?

Soluzione

Sembra che ciò che accada se duplica il codice dell'evento.Fai uno sguardo vicino ai tuoi nomi di controllo e assicurati che corrispondano.Inoltre, ti consigliamo di assicurarsi che [procedura evento] appaia nelle proprietà dell'evento.Quel collegamento potrebbe non apparire automaticamente se si modificano i nomi di controllo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top