Boucle en vba access

Résolu/Fermé
bithack Messages postés 129 Date d'inscription mercredi 29 octobre 2014 Statut Membre Dernière intervention 16 mars 2016 - 5 mai 2015 à 09:25
bithack Messages postés 129 Date d'inscription mercredi 29 octobre 2014 Statut Membre Dernière intervention 16 mars 2016 - 6 mai 2015 à 15:57
Bonjour à tous,
Voila je reviens vers vous car je ne vois pas comment mettre et faire ma boucle.
Je voudrai que ma variable flag ( qui correspond a date resil) change
Sub sortieRun()
Dim jour As String
Dim db As Database
Dim sSQL0 As String
Dim sSQL1 As String
Dim sSQL2 As String
Dim sSQL3 As String
Dim sSQL4 As String
Dim sSQL5 As String
Dim flag As DAO.Recordset
Dim run As DAO.Recordset
Dim typerun As DAO.Recordset
Dim rstest As DAO.Recordset
Dim rsdate As DAO.Recordset
Dim rscal As DAO.Recordset
Dim rs As DAO.Recordset
Dim i As Integer
Dim okay As DAO.Recordset





jour = Date
MsgBox jour ' affiche la date du jour

Set db = CurrentDb
Set rstest = db.OpenRecordset("test")

sSQL0 = "select date_resil FROM Dossier;"
Set flag = db.OpenRecordset(sSQL0)

sSQL3 = "select run FROM Dossier;"
Set run = db.OpenRecordset(sSQL3)

sSQL5 = "select okko FROM Dossier;"
Set okay = db.OpenRecordset(sSQL5)

With rstest
.AddNew
.Fields("date_resil") = flag.Fields("date_resil")
.Fields("run") = run.Fields("run")
.Update
dr = flag.Fields("date_resil")
MsgBox dr
rn = run.Fields("run")
MsgBox rn

End With

Set rscal = db.OpenRecordset("calendrier")
sSQL4 = " select run" & rn & " FROM calendrier;"
Set rs = db.OpenRecordset(sSQL4)
rs.MoveFirst
i = 1
essai = rs.Fields("run" & rn & "")
MsgBox essai
i = 1
If dr > essai And essai < jour Then
With okay
.Edit
.Fields("okko") = "ok"
.Update
End With
Else
i = i + 1
rs.MoveNext
End If
i = i + 1
rs.MoveNext









End Sub


merci par avance :)


1 réponse

f894009 Messages postés 17205 Date d'inscription dimanche 25 novembre 2007 Statut Membre Dernière intervention 19 octobre 2024 1 709
5 mai 2015 à 10:46
Bonjour,

modif pour evolution recordset flag, mais quand est-il du recordset rs ??

Sub sortieRun()
Dim jour As String
Dim db As Database
Dim sSQL0 As String
Dim sSQL1 As String
Dim sSQL2 As String
'Dim sSQL3 As String
Dim sSQL4 As String
'Dim sSQL5 As String
Dim flag As DAO.Recordset
'Dim run As DAO.Recordset
Dim typerun As DAO.Recordset
Dim rstest As DAO.Recordset
Dim rsdate As DAO.Recordset
'Dim rscal As DAO.Recordset
Dim rs As DAO.Recordset
'Dim i As Integer
'Dim okay As DAO.Recordset

jour = Date
MsgBox jour ' affiche la date du jour

Set db = CurrentDb
Set rstest = db.OpenRecordset("test")

sSQL0 = "select date_resil,run,okko FROM Dossier;"
Set flag = db.OpenRecordset(sSQL0)

'sSQL3 = "select run FROM Dossier;"
'Set run = db.OpenRecordset(sSQL3)

'sSQL5 = "select okko FROM Dossier;"
'Set okay = db.OpenRecordset(sSQL5)
flag.MoveFirst
Do While Not flag.EOF
With rstest
.AddNew
.Fields("date_resil") = flag.Fields("date_resil")
.Fields("run") = flag.Fields("run")
.Update
dr = flag.Fields("date_resil")
MsgBox dr
rn = flag.Fields("run")
MsgBox rn
End With

'Set rscal = db.OpenRecordset("calendrier")
sSQL4 = " select run" & rn & " FROM calendrier;"
Set rs = db.OpenRecordset(sSQL4)
rs.MoveFirst
'--------------------------------------
essai = rs.Fields("run" & rn & "")
MsgBox essai
If dr > essai And essai < jour Then
With flag
.Edit
.Fields("okko") = "ok"
.Update
End With
End If
'-------------------------------------
flag.MoveNext
Loop
End Sub
0
bithack Messages postés 129 Date d'inscription mercredi 29 octobre 2014 Statut Membre Dernière intervention 16 mars 2016 6
6 mai 2015 à 15:57
Merci :)
0