Je souhaite récupérer la valeur des champs d'un enregistrement d'une table.
Pour récupérer un champ, il y a l'instruction Dlookup.
Pour récupérer tous les champs de l'enregistrement, y a-t-il une méthode
plus simple que la suivante qui déroule toute la table :
Set db = CurrentDb()
Set rst = db.OpenRecordset("Clients")
Do While Not rst.EOF
If rst![No] = no_client Then
no = rst![No]
nom_client = rst![Nom_client]
prenom = rst![Prenom]
rue = rst![Rue]
rue_complement = rst![Rue_complement]
code_postal = rst![Code_postal]
ville = rst![Ville]
pays = rst![Pays]
Exit Do
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Set db = CurrentDb() Set rst = db.OpenRecordset("Clients") Do While Not rst.EOF If rst![No] = no_client Then no = rst![No] nom_client = rst![Nom_client] prenom = rst![Prenom] rue = rst![Rue] rue_complement = rst![Rue_complement] code_postal = rst![Code_postal] ville = rst![Ville] pays = rst![Pays] Exit Do End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing
Merci d'avance.
Salut,
JV wrote:
Je souhaite récupérer la valeur des champs d'un enregistrement d'une
table.
Pour récupérer un champ, il y a l'instruction Dlookup.
Pour récupérer tous les champs de l'enregistrement, y a-t-il une
méthode plus simple que la suivante qui déroule toute la table :
Oui, renseigner une source au formulaire...
pourquoi cela n'en est-il pas ainsi ?
Set db = CurrentDb()
Set rst = db.OpenRecordset("Clients")
Do While Not rst.EOF
If rst![No] = no_client Then
no = rst![No]
nom_client = rst![Nom_client]
prenom = rst![Prenom]
rue = rst![Rue]
rue_complement = rst![Rue_complement]
code_postal = rst![Code_postal]
ville = rst![Ville]
pays = rst![Pays]
Exit Do
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Set db = CurrentDb() Set rst = db.OpenRecordset("Clients") Do While Not rst.EOF If rst![No] = no_client Then no = rst![No] nom_client = rst![Nom_client] prenom = rst![Prenom] rue = rst![Rue] rue_complement = rst![Rue_complement] code_postal = rst![Code_postal] ville = rst![Ville] pays = rst![Pays] Exit Do End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing
Merci d'avance.
jero
Salut, Qques autres méthodes : Sub Méthode2(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * Clients WHERE [No]=" & NumEnreg) With Rst Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode3(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("Clients") With Rst .Index = "PrimaryKey" .Seek "=", NumEnreg If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode4(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset, Critère As String Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * FROM Clients") Critère = "[No]=" & NumEnreg With Rst .FindFirst (Critère) If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub Note : la méthode la plus rapide est la n°3 (avec un index)
"3stone" a écrit dans le message de news: %
Salut,
JV wrote:
Je souhaite récupérer la valeur des champs d'un enregistrement d'une table.
Pour récupérer un champ, il y a l'instruction Dlookup.
Pour récupérer tous les champs de l'enregistrement, y a-t-il une méthode plus simple que la suivante qui déroule toute la table :
Oui, renseigner une source au formulaire... pourquoi cela n'en est-il pas ainsi ?
Set db = CurrentDb() Set rst = db.OpenRecordset("Clients") Do While Not rst.EOF If rst![No] = no_client Then no = rst![No] nom_client = rst![Nom_client] prenom = rst![Prenom] rue = rst![Rue] rue_complement = rst![Rue_complement] code_postal = rst![Code_postal] ville = rst![Ville] pays = rst![Pays] Exit Do End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing
Merci d'avance.
Salut,
Qques autres méthodes :
Sub Méthode2(NumEnreg As Long)
Dim Db As DAO.Database, Rst As DAO.Recordset
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("SELECT * Clients WHERE [No]=" & NumEnreg)
With Rst
Code_Postal = ![Code_Postal]
Ville = ![Ville]
Pays = ![Pays]
.Close
End With
Set Rst = Nothing
Set Db = Nothing
End Sub
Sub Méthode3(NumEnreg As Long)
Dim Db As DAO.Database, Rst As DAO.Recordset
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("Clients")
With Rst
.Index = "PrimaryKey"
.Seek "=", NumEnreg
If Not .NoMatch Then
Code_Postal = ![Code_Postal]
Ville = ![Ville]
Pays = ![Pays]
End If
.Close
End With
Set Rst = Nothing
Set Db = Nothing
End Sub
Sub Méthode4(NumEnreg As Long)
Dim Db As DAO.Database, Rst As DAO.Recordset, Critère As String
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("SELECT * FROM Clients")
Critère = "[No]=" & NumEnreg
With Rst
.FindFirst (Critère)
If Not .NoMatch Then
Code_Postal = ![Code_Postal]
Ville = ![Ville]
Pays = ![Pays]
End If
.Close
End With
Set Rst = Nothing
Set Db = Nothing
End Sub
Note : la méthode la plus rapide est la n°3 (avec un index)
"3stone" <home@sweet_home.be> a écrit dans le message de news:
%23dp2njZrKHA.5356@TK2MSFTNGP02.phx.gbl...
Salut,
JV wrote:
Je souhaite récupérer la valeur des champs d'un enregistrement d'une
table.
Pour récupérer un champ, il y a l'instruction Dlookup.
Pour récupérer tous les champs de l'enregistrement, y a-t-il une
méthode plus simple que la suivante qui déroule toute la table :
Oui, renseigner une source au formulaire...
pourquoi cela n'en est-il pas ainsi ?
Set db = CurrentDb()
Set rst = db.OpenRecordset("Clients")
Do While Not rst.EOF
If rst![No] = no_client Then
no = rst![No]
nom_client = rst![Nom_client]
prenom = rst![Prenom]
rue = rst![Rue]
rue_complement = rst![Rue_complement]
code_postal = rst![Code_postal]
ville = rst![Ville]
pays = rst![Pays]
Exit Do
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Salut, Qques autres méthodes : Sub Méthode2(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * Clients WHERE [No]=" & NumEnreg) With Rst Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode3(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("Clients") With Rst .Index = "PrimaryKey" .Seek "=", NumEnreg If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode4(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset, Critère As String Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * FROM Clients") Critère = "[No]=" & NumEnreg With Rst .FindFirst (Critère) If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub Note : la méthode la plus rapide est la n°3 (avec un index)
"3stone" a écrit dans le message de news: %
Salut,
JV wrote:
Je souhaite récupérer la valeur des champs d'un enregistrement d'une table.
Pour récupérer un champ, il y a l'instruction Dlookup.
Pour récupérer tous les champs de l'enregistrement, y a-t-il une méthode plus simple que la suivante qui déroule toute la table :
Oui, renseigner une source au formulaire... pourquoi cela n'en est-il pas ainsi ?
Set db = CurrentDb() Set rst = db.OpenRecordset("Clients") Do While Not rst.EOF If rst![No] = no_client Then no = rst![No] nom_client = rst![Nom_client] prenom = rst![Prenom] rue = rst![Rue] rue_complement = rst![Rue_complement] code_postal = rst![Code_postal] ville = rst![Ville] pays = rst![Pays] Exit Do End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing
Merci d'avance.
JV
Merci à tous les deux
"jero" <~ a écrit dans le message de news:
Salut, Qques autres méthodes : Sub Méthode2(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * Clients WHERE [No]=" & NumEnreg) With Rst Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode3(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("Clients") With Rst .Index = "PrimaryKey" .Seek "=", NumEnreg If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode4(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset, Critère As String Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * FROM Clients") Critère = "[No]=" & NumEnreg With Rst .FindFirst (Critère) If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub Note : la méthode la plus rapide est la n°3 (avec un index)
"3stone" a écrit dans le message de news: % > Salut, > > JV wrote: >> Je souhaite récupérer la valeur des champs d'un enregistrement d'une >> table. >> >> Pour récupérer un champ, il y a l'instruction Dlookup. >> >> Pour récupérer tous les champs de l'enregistrement, y a-t-il une >> méthode plus simple que la suivante qui déroule toute la table : > > > Oui, renseigner une source au formulaire... > pourquoi cela n'en est-il pas ainsi ? > > > -- > A+ > Pierre (3stone) Access MVP > Perso: http://www.3stone.be/ > MPFA: http://www.mpfa.info/ (infos générales) > > > >> Set db = CurrentDb() >> Set rst = db.OpenRecordset("Clients") >> Do While Not rst.EOF >> If rst![No] = no_client Then >> no = rst![No] >> nom_client = rst![Nom_client] >> prenom = rst![Prenom] >> rue = rst![Rue] >> rue_complement = rst![Rue_complement] >> code_postal = rst![Code_postal] >> ville = rst![Ville] >> pays = rst![Pays] >> Exit Do >> End If >> rst.MoveNext >> Loop >> rst.Close >> Set rst = Nothing >> Set db = Nothing >> >> Merci d'avance. >
Merci à tous les deux
"jero" <~jero@jero.net> a écrit dans le message de news:
uwCQIwZrKHA.3800@TK2MSFTNGP06.phx.gbl...
Salut,
Qques autres méthodes :
Sub Méthode2(NumEnreg As Long)
Dim Db As DAO.Database, Rst As DAO.Recordset
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("SELECT * Clients WHERE [No]=" & NumEnreg)
With Rst
Code_Postal = ![Code_Postal]
Ville = ![Ville]
Pays = ![Pays]
.Close
End With
Set Rst = Nothing
Set Db = Nothing
End Sub
Sub Méthode3(NumEnreg As Long)
Dim Db As DAO.Database, Rst As DAO.Recordset
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("Clients")
With Rst
.Index = "PrimaryKey"
.Seek "=", NumEnreg
If Not .NoMatch Then
Code_Postal = ![Code_Postal]
Ville = ![Ville]
Pays = ![Pays]
End If
.Close
End With
Set Rst = Nothing
Set Db = Nothing
End Sub
Sub Méthode4(NumEnreg As Long)
Dim Db As DAO.Database, Rst As DAO.Recordset, Critère As String
Set Db = CurrentDb()
Set Rst = Db.OpenRecordset("SELECT * FROM Clients")
Critère = "[No]=" & NumEnreg
With Rst
.FindFirst (Critère)
If Not .NoMatch Then
Code_Postal = ![Code_Postal]
Ville = ![Ville]
Pays = ![Pays]
End If
.Close
End With
Set Rst = Nothing
Set Db = Nothing
End Sub
Note : la méthode la plus rapide est la n°3 (avec un index)
"3stone" <home@sweet_home.be> a écrit dans le message de news:
%23dp2njZrKHA.5356@TK2MSFTNGP02.phx.gbl...
> Salut,
>
> JV wrote:
>> Je souhaite récupérer la valeur des champs d'un enregistrement d'une
>> table.
>>
>> Pour récupérer un champ, il y a l'instruction Dlookup.
>>
>> Pour récupérer tous les champs de l'enregistrement, y a-t-il une
>> méthode plus simple que la suivante qui déroule toute la table :
>
>
> Oui, renseigner une source au formulaire...
> pourquoi cela n'en est-il pas ainsi ?
>
>
> --
> A+
> Pierre (3stone) Access MVP
> Perso: http://www.3stone.be/
> MPFA: http://www.mpfa.info/ (infos générales)
>
>
>
>> Set db = CurrentDb()
>> Set rst = db.OpenRecordset("Clients")
>> Do While Not rst.EOF
>> If rst![No] = no_client Then
>> no = rst![No]
>> nom_client = rst![Nom_client]
>> prenom = rst![Prenom]
>> rue = rst![Rue]
>> rue_complement = rst![Rue_complement]
>> code_postal = rst![Code_postal]
>> ville = rst![Ville]
>> pays = rst![Pays]
>> Exit Do
>> End If
>> rst.MoveNext
>> Loop
>> rst.Close
>> Set rst = Nothing
>> Set db = Nothing
>>
>> Merci d'avance.
>
Salut, Qques autres méthodes : Sub Méthode2(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * Clients WHERE [No]=" & NumEnreg) With Rst Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode3(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset Set Db = CurrentDb() Set Rst = Db.OpenRecordset("Clients") With Rst .Index = "PrimaryKey" .Seek "=", NumEnreg If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub
Sub Méthode4(NumEnreg As Long) Dim Db As DAO.Database, Rst As DAO.Recordset, Critère As String Set Db = CurrentDb() Set Rst = Db.OpenRecordset("SELECT * FROM Clients") Critère = "[No]=" & NumEnreg With Rst .FindFirst (Critère) If Not .NoMatch Then Code_Postal = ![Code_Postal] Ville = ![Ville] Pays = ![Pays] End If .Close End With Set Rst = Nothing Set Db = Nothing End Sub Note : la méthode la plus rapide est la n°3 (avec un index)
"3stone" a écrit dans le message de news: % > Salut, > > JV wrote: >> Je souhaite récupérer la valeur des champs d'un enregistrement d'une >> table. >> >> Pour récupérer un champ, il y a l'instruction Dlookup. >> >> Pour récupérer tous les champs de l'enregistrement, y a-t-il une >> méthode plus simple que la suivante qui déroule toute la table : > > > Oui, renseigner une source au formulaire... > pourquoi cela n'en est-il pas ainsi ? > > > -- > A+ > Pierre (3stone) Access MVP > Perso: http://www.3stone.be/ > MPFA: http://www.mpfa.info/ (infos générales) > > > >> Set db = CurrentDb() >> Set rst = db.OpenRecordset("Clients") >> Do While Not rst.EOF >> If rst![No] = no_client Then >> no = rst![No] >> nom_client = rst![Nom_client] >> prenom = rst![Prenom] >> rue = rst![Rue] >> rue_complement = rst![Rue_complement] >> code_postal = rst![Code_postal] >> ville = rst![Ville] >> pays = rst![Pays] >> Exit Do >> End If >> rst.MoveNext >> Loop >> rst.Close >> Set rst = Nothing >> Set db = Nothing >> >> Merci d'avance. >
Mehdi HAMMADI
Bonjour M. Pierre, Je ne comprend pas ce que vous voulez dire par renseigner une source au formulaire Merci de m'orienter un peut plus.
Set db = CurrentDb() Set rst = db.OpenRecordset("Clients") Do While Not rst.EOF If rst![No] = no_client Then no = rst![No] nom_client = rst![Nom_client] prenom = rst![Prenom] rue = rst![Rue] rue_complement = rst![Rue_complement] code_postal = rst![Code_postal] ville = rst![Ville] pays = rst![Pays] Exit Do End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing
Merci d'avance.
Bonjour M. Pierre,
Je ne comprend pas ce que vous voulez dire par renseigner une source au
formulaire
Merci de m'orienter un peut plus.
Set db = CurrentDb()
Set rst = db.OpenRecordset("Clients")
Do While Not rst.EOF
If rst![No] = no_client Then
no = rst![No]
nom_client = rst![Nom_client]
prenom = rst![Prenom]
rue = rst![Rue]
rue_complement = rst![Rue_complement]
code_postal = rst![Code_postal]
ville = rst![Ville]
pays = rst![Pays]
Exit Do
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
Set db = Nothing
Set db = CurrentDb() Set rst = db.OpenRecordset("Clients") Do While Not rst.EOF If rst![No] = no_client Then no = rst![No] nom_client = rst![Nom_client] prenom = rst![Prenom] rue = rst![Rue] rue_complement = rst![Rue_complement] code_postal = rst![Code_postal] ville = rst![Ville] pays = rst![Pays] Exit Do End If rst.MoveNext Loop rst.Close Set rst = Nothing Set db = Nothing
Merci d'avance.
Michel__D
Bonjour,
Si tu ne comprends pas; laisse tomber c'est plus simple.
PS: Avant que l'on t'oriente, pose toi la question de ce que tu cherche à faire, tu auras alors un début de réponse.
Mehdi HAMMADI a écrit :
Bonjour M. Pierre, Je ne comprend pas ce que vous voulez dire par renseigner une source au formulaire Merci de m'orienter un peut plus.