Comment utiliser la tvd.FindFirst avec la tvd.NoMatch?

Mon code fonctionne, sauf pour ce seul ligne

.FindFirst "[DONOR_CONTACT_ID] = strTemp2"

Je veux mon code pour vérifier si il y a un enregistrement, où une DONOR_CONTACT_ID existe parce que il y a plusieurs enregistrements avec le même DONOR_CONTACT_ID. Si cet enregistrement n'existe pas, alors je tiens à ajouter que DONOR_CONTACT_ID et RECIPIENT_CONTACT_ID à RECIPIENT_1. Si l'enregistrement n'existe pas, je veux ajouter le RECIPIENT_CONTACT_ID à RECIPIENT_2 pour DONOR_CONTACT_ID. Pour ce faire, j'ai utilisé .FindFirst, pour voir si il y avait un enregistrement, puis utilisé .NoMatch. Si il n'y a pas un match, je veux ajouter un nouvel enregistrement, mais si je veux vérifier pour voir si elle doit aller dans RECIPIENT_2.

L'erreur que j'obtiens est "ne reconnaît pas "strTemp2" comme un nom de champ valide ou d'expression". Je veux voir si l'enregistrement est égale à strTemp2, mais je pense que ma syntaxe est incorrecte. Merci pour toute aide!!

Voici mon code:

Option Compare Database
Option Explicit
Function UsingTemps()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim rstOutput As DAO.Recordset
'Defines DAO objects
Dim strTemp1 As String
Dim strTemp2 As String
Dim strVal As String
Dim strRecip As String
DoCmd.SetWarnings False
DoCmd.OpenQuery ("Q_RECIPIENT_SORT")
DoCmd.OpenQuery ("Q_DELETE_T_OUTPUT")
DoCmd.SetWarnings True
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("T_RECIPIENT_SORT", dbOpenDynaset)
'rst refers to the table T_RECIPIENT_SORT
Set rstOutput = dbs.OpenRecordset("T_OUTPUT", dbOpenDynaset)
'rstOutput refers to the table T_OUTPUT
rst.MoveFirst
'first record
strTemp1 = rst!DONOR_CONTACT_ID
'sets strTemp1 to the first record of the DONOR_CONTACT_ID
rst.MoveNext
'moves to the next record
Do While Not rst.EOF
'Loop while it's not the end of the file
strTemp2 = rst!DONOR_CONTACT_ID
'strTemp2 = DONOR_CONTACT_ID from T_RECIPIENT_SORT
If strTemp1 = strTemp2 Then
'Runs if temps have same DONOR_CONTACT ID
strRecip = rst!RECIPIENT_CONTACT_ID
'Sets strRecip = RECIPIENT_CONTACT_ID FROM T_RECIPIENT_SORT
With rstOutput
'Uses T_OUTPUT table
If .RecordCount > 0 Then
'If table has records then you can check
.FindFirst "[DONOR_CONTACT_ID] = strTemp2"
If .NoMatch Then
.AddNew
!DONOR_CONTACT_ID = strTemp1
!RECIPIENT_1 = strRecip
.Update
Else
If !DONOR_CONTACT_ID = strTemp2 Then
If IsNull(!RECIPIENT_2) And Not (IsNull(!RECIPIENT_1)) Then
.Edit
!RECIPIENT_2 = strRecip
.Update
End If
.AddNew
!DONOR_CONTACT_ID = strTemp2
!RECIPIENT_1 = strRecip
.Update
End If
End If
Else
.AddNew
!DONOR_CONTACT_ID = strTemp2
!RECIPIENT_1 = strRecip
.Update
End If
End With
End If
strTemp1 = strTemp2
rst.MoveNext
Loop
Set dbs = Nothing
End Function
InformationsquelleAutor nedstark179 | 2013-07-12