loop coding

mazza

Registered User.
Local time
Today, 09:40
Joined
Feb 9, 2005
Messages
101
I have a table TblServicebySerialSummary
one field is a next service date. the interva is based on the formula (365 / (AvgRunHrs / ServiceInt))

I want to take the first date in first record of the field [plannedServicedate] to stay as it is, but the next record the date should read + (365 / (AvgRunHrs / ServiceInt)) and the 3rd record should read the vlaue of the second row + (365 / (AvgRunHrs / ServiceInt)) etc etc.


First of all I tried to create this code but it failed miserably

first of all I got this message
the microsoft Jet database engine cannot find the input table or query ....

hwr I am sure that there is a lot wrong with this code...

Help Anybody .....

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim f As Date
Dim g As Integer

g = (365 / (AvgRunHrs / ServiceInt))

Set db = CurrentDb()
Set rs = db.OpenRecordset(TblServicebySerialSummary)
With rs
.FindFirst [plannedServicedate]
.MoveNext
[plannedServicedate] = [plannedServicedate] + g
f = [plannedServicedate]
Do While Not EOF(1)
.MoveNext
[plannedServicedate] = [plannedServicedate] + g
f = [plannedServicedate]
Loop
End With
 
you need quotes and try using the code tags to make it look nicer like I did (just quote my text and you will see how I did it)
Code:
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim f As Date
    Dim g As Integer

    g = (365 / (AvgRunHrs / ServiceInt))
    
    Set db = CurrentDb()
    Set rs = db.OpenRecordset("TblServicebySerialSummary")
    With rs
    .FindFirst [plannedServicedate]
    .MoveNext
    [plannedServicedate] = [plannedServicedate] + g
    f = [plannedServicedate]
    Do While Not EOF(1)
    .MoveNext
    [plannedServicedate] = [plannedServicedate] + g
    f = [plannedServicedate]
    Loop
End With
 
thanks so obvious it is actually painfull but now I get the message
"cannot find the field "|" refered to in your expression"

changed code to
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim f As Date
Dim g As Integer

g = 365 / (AvgRunHrs / ServiceInt)

Set db = CurrentDb()
Set rs = db.OpenRecordset("TblServicebySerialSummary")
With rs
.FindFirst [plannedServicedate]
.MoveNext
[plannedServicedate] = [plannedServicedate] + g
f = [plannedServicedate]
Do While Not EOF(1)
.MoveNext
[plannedServicedate] = [plannedServicedate] + g
f = [plannedServicedate]
Loop

End With
 

Users who are viewing this thread

Back
Top Bottom