473,379 Members | 1,191 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

How do I loop through records

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.?
Nov 13 '05 #1
3 53011
Anderson wrote:
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.?

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.

Nov 13 '05 #2
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:
Anderson wrote:
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.?

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.


Nov 13 '05 #3
Anderson wrote:
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:
Anderson wrote:
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.?

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.

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.
Nov 13 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
3
by: Charles Ranch | last post by:
Hello, I'll bet this is an elementary question. I have a text file I am converting and posting to a SQL database. But the first 15 records in this text file are going into a NOTES field in the...
5
by: !TG | last post by:
I currently use Do while loop, but I'd rather use a For Loop though I have never gotten the hang of them. Would some one please be so kind as to show me how to loop through a recordset.
6
by: Michael Goerz | last post by:
Hi, I'm trying to write a loop that cycles through all the records. This I use for doing comparisons between all records or to export all records to a text file. I'm using the following code: ...
2
by: JC | last post by:
Hi, I have a database that imports 4 reports to my "data" table, each report has its own identifier. Then I have a table with Analysts with the report identifier that they are to be assigned to. ...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
8
by: SaltyBoat | last post by:
Needing to import and parse data from a large PDF file into an Access 2002 table: I start by converted the PDF file to a html file. Then I read this html text file, line by line, into a table...
6
by: VivDenham | last post by:
Hi there I am brand new to VBA - a 61 year old lady who likes machine knitting. For the last couple of years, I have been designing an Access database called Knitting Database. I want a...
5
by: bigukfan | last post by:
I am producing a statistic for one of the managers at work concerning hospital patients. I have a database with about 120 tables, some of which relate to a set of patients. All the table names I am...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.