[vba access] Editer une ligne de table

Résolu/Fermé
stikmou08 Messages postés 27 Date d'inscription jeudi 10 février 2011 Statut Membre Dernière intervention 16 mars 2018 - 23 févr. 2011 à 13:20
stikmou08 Messages postés 27 Date d'inscription jeudi 10 février 2011 Statut Membre Dernière intervention 16 mars 2018 - 25 févr. 2011 à 13:41
Bonjour à tous,

j'ai un petit soucis d'édition de ma table en code. En effet j'utilise un recordset pour editer ma table, mais le problème, c'est qu'il édite la premier ligne de ma table et non celle voulue.
Jevous met mon code :
Set RST2 = CurrentDb.OpenRecordset("STOCK", dbOpenTable)
Set RST3 = CurrentDb.OpenRecordset("select code,reference,taille from STOCK where code = '" & Me.TextBox4 & "' and reference = '" & Me.TextBox7 & "' and taille = '" & Me.ComboBox0 & "'")


        If RST3.RecordCount = 0 Then
            With RST2
                .AddNew
                .Fields("code") = Me.TextBox4
                .Fields("reference") = Me.TextBox7
                .Fields("taille") = Me.ComboBox0
                    If Me.ComboBox1 = "E" Then
                        .Fields("quantite_entre") = Me.TextBox2
                    ElseIf Me.ComboBox1 = "S" Then
                        .Fields("quantite_sortie") = Me.TextBox2
                    End If
                .Fields("quantite_totale") = .Fields("quantite_entre").Value - .Fields("quantite_sortie").Value
                .Update
            End With
        Else
            With RST2
                .Edit
                If Me.ComboBox1 = "E" Then
                    .Fields("quantite_entre") = Me.TextBox2 + .Fields("quantite_entre").Value
                ElseIf Me.ComboBox1 = "S" Then
                    .Fields("quantite_sortie") = Me.TextBox2 + .Fields("quantite_sortie").Value
                End If
                    .Fields("quantite_totale") = .Fields("quantite_entre").Value - .Fields("quantite_sortie").Value
                .Update
            End With
        End If


Donc c'est quand il rentre dans la boucle Else, with RST2, .edit que ca ne fonctionne pas. Du moins ca fonctionne, car il edite bien la premiere ligne, mais moi je voudrai qu'il edite la ligne qu'il a trouver dans le recordset 3 (RST3)
Je ne sais pas si je suis très clair. Merci de votre compréhension.

A voir également:

1 réponse

Polux31 Messages postés 6917 Date d'inscription mardi 25 septembre 2007 Statut Membre Dernière intervention 1 novembre 2016 1 204
24 févr. 2011 à 14:57
Bonjour,

A aucun moment tu utilises RST3 !!!

Je ne vois pas bien à quoi il sert d'ailleurs ... Ôo ....



1
stikmou08 Messages postés 27 Date d'inscription jeudi 10 février 2011 Statut Membre Dernière intervention 16 mars 2018 2
25 févr. 2011 à 08:06
Je l'utilise pour ma boucle If
If RST3.RecordCount = 0 Then

Il sert à savoir si une ligne de ma table avec les information de la textbox4, textbox7, combobox0 existe ou non.
0
Polux31 Messages postés 6917 Date d'inscription mardi 25 septembre 2007 Statut Membre Dernière intervention 1 novembre 2016 1 204
25 févr. 2011 à 13:27
Oui ça j'ai compris. Mais ensuite ???

Je ferai comme ça :

Set RST3 = "CurrentDb.OpenRecordset("select * from STOCK where code = '" & Me.TextBox4 & "' and reference = '" & Me.TextBox7 & "' and taille = '" & Me.ComboBox0 & "'")


Et ensuite :

If RST3.RecordCount <> 0 Then
            With RST3
                .Edit
                If Me.ComboBox1 = "E" Then
                    .Fields("quantite_entre") = Me.TextBox2 + .Fields("quantite_entre").Value
                ElseIf Me.ComboBox1 = "S" Then
                    .Fields("quantite_sortie") = Me.TextBox2 + .Fields("quantite_sortie").Value
                End If
                    .Fields("quantite_totale") = .Fields("quantite_entre").Value - .Fields("quantite_sortie").Value
                .Update
            End With
        RST3.Close
        Set RST3 = Nothing

  Else

        Set RST2 = CurrentDb.OpenRecordset("STOCK", dbOpenTable)

        With RST2
                .AddNew
                .Fields("code") = Me.TextBox4
                .Fields("reference") = Me.TextBox7
                .Fields("taille") = Me.ComboBox0
                    If Me.ComboBox1 = "E" Then
                        .Fields("quantite_entre") = Me.TextBox2
                    ElseIf Me.ComboBox1 = "S" Then
                        .Fields("quantite_sortie") = Me.TextBox2
                    End If
                .Fields("quantite_totale") = .Fields("quantite_entre").Value - .Fields("quantite_sortie").Value
                .Update
            End With
            RST2.Close
            Set RST2 = Nothing
End If
0
stikmou08 Messages postés 27 Date d'inscription jeudi 10 février 2011 Statut Membre Dernière intervention 16 mars 2018 2
25 févr. 2011 à 13:41
Ca fonctionne très bien, je te remercie :)
0