1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Sub test()
Dim RS As DAO.Recordset
Dim EntreeRang4 As String
Dim EntreeRang6 As String
'préliminaire, afficher le contenu de la table
Set RS = CurrentDb.OpenRecordset("SELECT champs FROM latable;")
Do Until RS.EOF
Debug.Print RS!champs
RS.MoveNext
Loop
'1ere étape récupération des valeurs à échanger, modification dans la foulée du rang6
Set RS = CurrentDb.OpenRecordset("SELECT champs FROM latable;")
Do Until RS.EOF
If Round(RS.PercentPosition * RS.RecordCount / 100, 0) = 3 Then
EntreeRang4 = RS!champs
Debug.Print "ancienne valeur 4 = " & RS!champs
End If
If Round(RS.PercentPosition * RS.RecordCount / 100, 0) = 5 Then
EntreeRang6 = RS!champs
Debug.Print "ancienne valeur 6 = " & RS!champs
RS.Edit
RS!champs = EntreeRang4
RS.Update
End If
RS.MoveNext
Loop
'2e étape, modifier le rang4 et lui donner le rang6
Set RS = CurrentDb.OpenRecordset("SELECT champs FROM latable;")
Do Until RS.EOF
If Round(RS.PercentPosition * RS.RecordCount / 100, 0) = 3 Then
RS.Edit
RS!champs = EntreeRang6
RS.Update
End If
RS.MoveNext
Loop
'3e étape, vérifier que la modif a eu lieu:
Set RS = CurrentDb.OpenRecordset("SELECT champs FROM latable;")
Do Until RS.EOF
Debug.Print RS!champs
RS.MoveNext
Loop
Set RS = Nothing
End Sub |
Partager