Remarque
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de vous connecter ou de modifier des répertoires.
L’accès à cette page nécessite une autorisation. Vous pouvez essayer de modifier des répertoires.
S’applique à : Access 2013, Office 2013
Indique si un enregistrement particulier a été trouvé à l’aide de la méthodeSeek ou de l’une des méthodesFind (espaces de travail Microsoft Access uniquement).
Syntaxe
expression .NoMatch
expression Variable représentant un objet Recordset.
Remarques
Lorsque vous ouvrez ou créez un jeu d’enregistrements objet, son NoMatch propriété est définie sur faux.
Pour rechercher un enregistrement, utilisez la méthode Seek sur un objet Recordset de type table ou l'une des méthodes Find sur un objet Recordset de type feuille de réponse dynamique ou instantané. Vérifiez le paramètre de la propriété NoMatch pour voir si l'enregistrement a pu être localisé.
Si la méthode Seek ou Find ne donne aucun résultat et que la propriété NoMatch a la valeur True, l'enregistrement actif ne sera plus valide. Veillez à obtenir le signet de l'enregistrement actif avant d'utiliser la méthode Seek ou l'une des méthodes Find si vous devez revenir à cet enregistrement.
Remarque
À l’aide de la déplacer méthodes sur un jeu d’enregistrements objet n’affecte pas son NoMatch paramètre de la propriété.
Exemple
Cet exemple utilise la propriété NoMatch pour déterminer si l'exécution d'une méthode Seek et d'une méthode FindFirst a donné des résultats, et, si ce n'est pas le cas, pour en indiquer la raison. Les fonctions SeekMatch et FindMatch sont nécessaires l'exécution de cette procédure.
Sub NoMatchX()
Dim dbsNorthwind As Database
Dim rstProducts As Recordset
Dim rstCustomers As Recordset
Dim strMessage As String
Dim strSeek As String
Dim strCountry As String
Dim varBookmark As Variant
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' Default is dbOpenTable; required if Index property will
' be used.
Set rstProducts = dbsNorthwind.OpenRecordset("Products")
With rstProducts
.Index = "PrimaryKey"
Do While True
' Show current record information; ask user for
' input.
strMessage = "NoMatch with Seek method" & vbCr & _
"Product ID: " & !ProductID & vbCr & _
"Product Name: " & !ProductName & vbCr & _
"NoMatch = " & .NoMatch & vbCr & vbCr & _
"Enter a product ID."
strSeek = InputBox(strMessage)
If strSeek = "" Then Exit Do
' Call procedure that seeks for a record based on
' the ID number supplied by the user.
SeekMatch rstProducts, Val(strSeek)
Loop
.Close
End With
Set rstCustomers = dbsNorthwind.OpenRecordset( _
"SELECT CompanyName, Country FROM Customers " & _
"ORDER BY CompanyName", dbOpenSnapshot)
With rstCustomers
Do While True
' Show current record information; ask user for
' input.
strMessage = "NoMatch with FindFirst method" & _
vbCr & "Customer Name: " & !CompanyName & _
vbCr & "Country: " & !Country & vbCr & _
"NoMatch = " & .NoMatch & vbCr & vbCr & _
"Enter country on which to search."
strCountry = Trim(InputBox(strMessage))
If strCountry = "" Then Exit Do
' Call procedure that finds a record based on
' the country name supplied by the user.
FindMatch rstCustomers, _
"Country = '" & strCountry & "'"
Loop
.Close
End With
dbsNorthwind.Close
End Sub
Sub SeekMatch(rstTemp As Recordset, _
intSeek As Integer)
Dim varBookmark As Variant
Dim strMessage As String
With rstTemp
' Store current record location.
varBookmark = .Bookmark
.Seek "=", intSeek
' If Seek method fails, notify user and return to the
' last current record.
If .NoMatch Then
strMessage = _
"Not found! Returning to current record." & _
vbCr & vbCr & "NoMatch = " & .NoMatch
MsgBox strMessage
.Bookmark = varBookmark
End If
End With
End Sub
Sub FindMatch(rstTemp As Recordset, _
strFind As String)
Dim varBookmark As Variant
Dim strMessage As String
With rstTemp
' Store current record location.
varBookmark = .Bookmark
.FindFirst strFind
' If Find method fails, notify user and return to the
' last current record.
If .NoMatch Then
strMessage = _
"Not found! Returning to current record." & _
vbCr & vbCr & "NoMatch = " & .NoMatch
MsgBox strMessage
.Bookmark = varBookmark
End If
End With
End Sub
L’exemple suivant montre comment utiliser la méthode Seek pour rechercher un enregistrement dans un tableau lié.
Exemple de code fourni parMicrosoft Access 2010 Programmer’s Reference.
Sub TestSeek()
' Get the path to the external database that contains
' the tblCustomers table we're going to search.
Dim strMyExternalDatabase
Dim dbs As DAO.Database
Dim dbsExt As DAO.Database
Dim rst As DAO.Recordset
Dim tdf As DAO.TableDef
Set dbs = CurrentDb()
Set tdf = dbs.TableDefs("tblCustomers")
strMyExternalDatabase = Mid(tdf.Connect, 11)
'Open the database that contains the table that is linked
Set dbsExt = OpenDatabase(strMyExternalDatabase)
'Open a table-type recordset against the external table
Set rst = dbsExt.OpenRecordset("tblCustomers", dbOpenTable)
'Specify which index to search on
rst.Index = "PrimaryKey"
'Specify the criteria
rst.Seek "=", 123
'Check the result
If rst.NoMatch Then
MsgBox "Record not found."
Else
MsgBox "Customer name: " & rst!CustName
End If
rst.Close
dbs.Close
dbsExt.Close
Set rst = Nothing
Set tdf = Nothing
Set dbs = Nothing
End Sub