M
Muneer Mikel
Hi,
The following code is working fine, however when one record doesn't meet the
condition, the database skips this record without updating it. I tried to put
"Else : .MovePrevious", so it retest the same record again, however the
database goes into endless loop. How can I make the database to include this
record in the loop again, so it gets updated.
Thank you
Muneer
Dim dbs As Database
Dim rst As DAO.Recordset
Dim TableTemp As Integer
Dim varX As Integer
Set rst = CurrentDb.OpenRecordset("Select * from Main WHERE ThursTable Is
Null and RegistrationNo Is Not Null and Cancelled is Null")
Set dbs = CurrentDb
With rst
Do Until .EOF
TableTemp = Int((72 - 1 + 1) * Rnd + 1)
varX = Nz(DLookup("[NoOfSeats]", "ThursdayTable", "[TableNo] =" &
TableTemp), 0)
If varX >= ![Registrants] Then
.Edit
![ThursTable] = TableTemp
varX = varX - ![Registrants]
.Update
dbs.Execute "UPDATE ThursdayTable SET NoOfSeats = " & varX & "
WHERE TableNo = " & TableTemp & ";"
End If
.MoveNext
Loop
End With
Set rst = Nothing
Set dbs = Nothing
The following code is working fine, however when one record doesn't meet the
condition, the database skips this record without updating it. I tried to put
"Else : .MovePrevious", so it retest the same record again, however the
database goes into endless loop. How can I make the database to include this
record in the loop again, so it gets updated.
Thank you
Muneer
Dim dbs As Database
Dim rst As DAO.Recordset
Dim TableTemp As Integer
Dim varX As Integer
Set rst = CurrentDb.OpenRecordset("Select * from Main WHERE ThursTable Is
Null and RegistrationNo Is Not Null and Cancelled is Null")
Set dbs = CurrentDb
With rst
Do Until .EOF
TableTemp = Int((72 - 1 + 1) * Rnd + 1)
varX = Nz(DLookup("[NoOfSeats]", "ThursdayTable", "[TableNo] =" &
TableTemp), 0)
If varX >= ![Registrants] Then
.Edit
![ThursTable] = TableTemp
varX = varX - ![Registrants]
.Update
dbs.Execute "UPDATE ThursdayTable SET NoOfSeats = " & varX & "
WHERE TableNo = " & TableTemp & ";"
End If
.MoveNext
Loop
End With
Set rst = Nothing
Set dbs = Nothing