Salad
re: How do I loop through records
Anderson wrote:[color=blue]
> Thanks for this code. very much appreciated. One mor questions the
> variable "lngID" what is that supposedd to be? is the the same as the
> student ID or not?
>
> Salad wrote:
>[color=green]
>> Anderson wrote:
>>[color=darkred]
>>> What is the VBA format/code for looping through records. This is what
>>> I am trying to do.
>>>
>>> I have a table called appointments. A student can have as many
>>> appointments. This table has among other fields change date, reason
>>> and grade.
>>>
>>> I want to write a funnction which says:
>>>
>>> If change date > "certain date" and reason = "something new" and
>>> grade different from the previous record then out put something.
>>>
>>>
>>> How can I structure and write this please.?
>>>
>>>[/color]
>> I would select the records from a SQL statement and sort by Date
>> ascending. Then scan the results. Something like this
>>
>> Function ScanRecs(lngID As Long) As Boolean
>> DIm strSQL As STring
>> Dim rst As REcordset
>> strSQL = "Select * From StudentRecs Where StudentID = " & _
>> lngID & " Order By SomeDate"
>>
>> 'open the results read-only
>> Set rst = currentdb.openrecordset(strSQL,dbopensnapshot)
>> If rst.Recordcount > 0 then
>> rst.MoveFirst
>> Do while not rst.EOF
>> '....process
>> rst.MoveNext
>> Loop
>> Endif
>> End Function
>>
>> Drop the above code into a code module and start pressing F1 on the
>> methods and properties you need more info on.
>>[/color]
>[/color]
Functions, and subroutines, can have arguments passed to them. For
example, from the debug window I could enter
? SumIt(1,2)
and this will call the function SumIt.
Function SumIt(intA as Integer, intB as Integer) As Integer
Sumit = intA + intB
End Function
and will return an integer value of adding the two values together.
I will assume you would want to only scan the records of the current
student record so I set up an argument that gets the ID. The code I
wrote is pretty useless...I don't know the table/names...just providing
some code that demonstrates the methods/properties that you'd probably use. |