Question

J'ai du mal à comprendre cela pour compiler, il conserve une erreur de variable non définie lors de la compilation à "IncDntNo.Value".J'ai essayé de résoudre Incdntno comme entier mais que vous obteniez alors un qualificatif invalide.J'ai un code similaire qui fonctionne (voir le deuxième bloc de code).Je n'avais pas besoin de beaucoup de ce qui allait dans la partie de code de travail, donc je l'ai supprimé.Je serais tellement reconnaissant si quelqu'un peut souligner où je vais mal dans le premier bloc de code?Merci beaucoup

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 qui fonctionne:

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

Était-ce utile?

La solution

Cela ressemble à ce qui se passe si vous dupliquez un code d'événement.Regardez de près vos noms de contrôle et assurez-vous qu'ils correspondent.De plus, vous voudrez vous assurer que [Procédure d'événement] apparaît dans les propriétés de l'événement.Ce lien peut ne pas apparaître automatiquement si vous modifiez des noms de contrôle.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top