[Access] Fonction "Find"
Inspiron
-
ptilou -
ptilou -
Bonjour,
Je travaille sur une BDD permettant de gérer les entretiens des différents camions du parc d'une société.
Je dispose (entre autres) d'une table "entretiens" comprenant les champs suivants
numéro de l'entretien
Index lors de l'entretien (nombre de km de la machine)
Date de l'entretien
Celle-ci est stockée dans un RecordSet dans ma programmation
je suis actuellement en train de programmer une procédure dans un module VBA et je cale complètement sur la fonction "find"
Je voudrais que ma fonction Find me trouve l'index lors du dernier entretien effectué
Je suis obligé de rester dans du code VBA car cette fonction "find" n'est qu'une partie de ma procédure
Je suis assez novice en Access (c'est la première fois que je programme ^^)
Merci beaucoup pour vos réponses
Je travaille sur une BDD permettant de gérer les entretiens des différents camions du parc d'une société.
Je dispose (entre autres) d'une table "entretiens" comprenant les champs suivants
numéro de l'entretien
Index lors de l'entretien (nombre de km de la machine)
Date de l'entretien
Celle-ci est stockée dans un RecordSet dans ma programmation
je suis actuellement en train de programmer une procédure dans un module VBA et je cale complètement sur la fonction "find"
Je voudrais que ma fonction Find me trouve l'index lors du dernier entretien effectué
Je suis obligé de rester dans du code VBA car cette fonction "find" n'est qu'une partie de ma procédure
Je suis assez novice en Access (c'est la première fois que je programme ^^)
Merci beaucoup pour vos réponses
A voir également:
- [Access] Fonction "Find"
- Fonction si et - Guide
- Find and mount - Télécharger - Récupération de données
- Fonction miroir - Guide
- Exemple base de données access à télécharger gratuit - Forum Access
- Fonction moyenne excel - Guide
5 réponses
Peut-etre plus facilement comme ceci...
Tiré du help de access
Seek Method Example
This example demonstrates the Seek method by allowing the user to search for a product based on an ID number.
Sub SeekX()
Dim dbsNorthwind As Database
Dim rstProducts As Recordset
Dim intFirst As Integer
Dim intLast As Integer
Dim strMessage As String
Dim strSeek As String
Dim varBookmark As Variant
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' You must open a table-type Recordset to use an index,
' and hence the Seek method.
Set rstProducts = _
dbsNorthwind.OpenRecordset("Products", dbOpenTable)
With rstProducts
' Set the index.
.Index = "PrimaryKey"
' Get the lowest and highest product IDs.
.MoveLast
intLast = !ProductID
.MoveFirst
intFirst = !ProductID
Do While True
' Display current record information and ask user
' for ID number.
strMessage = "Product ID: " & !ProductID & vbCr & _
"Name: " & !ProductName & vbCr & vbCr & _
"Enter a product ID between " & intFirst & _
" and " & intLast & "."
strSeek = InputBox(strMessage)
If strSeek = "" Then Exit Do
' Store current bookmark in case the Seek fails.
varBookmark = .Bookmark
.Seek "=", Val(strSeek)
' Return to the current record if the Seek fails.
If .NoMatch Then
MsgBox "ID not found!"
.Bookmark = varBookmark
End If
Loop
.Close
End With
dbsNorthwind.Close
End Sub
Tiré du help de access
Seek Method Example
This example demonstrates the Seek method by allowing the user to search for a product based on an ID number.
Sub SeekX()
Dim dbsNorthwind As Database
Dim rstProducts As Recordset
Dim intFirst As Integer
Dim intLast As Integer
Dim strMessage As String
Dim strSeek As String
Dim varBookmark As Variant
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' You must open a table-type Recordset to use an index,
' and hence the Seek method.
Set rstProducts = _
dbsNorthwind.OpenRecordset("Products", dbOpenTable)
With rstProducts
' Set the index.
.Index = "PrimaryKey"
' Get the lowest and highest product IDs.
.MoveLast
intLast = !ProductID
.MoveFirst
intFirst = !ProductID
Do While True
' Display current record information and ask user
' for ID number.
strMessage = "Product ID: " & !ProductID & vbCr & _
"Name: " & !ProductName & vbCr & vbCr & _
"Enter a product ID between " & intFirst & _
" and " & intLast & "."
strSeek = InputBox(strMessage)
If strSeek = "" Then Exit Do
' Store current bookmark in case the Seek fails.
varBookmark = .Bookmark
.Seek "=", Val(strSeek)
' Return to the current record if the Seek fails.
If .NoMatch Then
MsgBox "ID not found!"
.Bookmark = varBookmark
End If
Loop
.Close
End With
dbsNorthwind.Close
End Sub
Oula c'est assez complexe tout ca pour moi... Pourrais tu essayer de me "décoder" tout ca ? Parce que je vois pas trop comment faire.
Merci
Merci
SEEK fait une recherche sur des champs indexés... Bcp + rapide que FindFirst qui est peut-être plus facile à coder en VBA
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question