Looping through a recordset

A

AJOLSON

This is my first venture down looping through record set and I am not really
sure of how it is done. But here is what I am trying to do. I have a query
where if a condition is me in one of the fields I want the field to backcolor
to turn to Vbred.
I have a query Named, TermType_Counts_Final and within that query I have a
field named OFF that return yes or no.

What I want is if the value is -1 “yesâ€, I want the backdrop to be vbred.
Below is the code I am using and what it is producing is that all values in
the filed “OFF†are coming back with a backcolor of vbred

Am I even on the right track?

Dim db As DAO.Database
Dim rst As DAO.Recordset



Set db = CurrentDb

Set rst = db.OpenRecordset("TermType_Counts_Final", dbOpenDynaset)

Do While Not rst.EOF
If rst![OFF] <> 0 Then 'The real loop exit condition.
Me.OFF.BackColor = vbRed
End If

rst.MoveNext
Loop

Any help would be greatly appreciated

Andy
 
D

Dale_Fye via AccessMonster.com

Is this a continuous form? My guess is yes.

In a continuous form, when you set a property of a particular field, it sets
the value of that field (control) for "ALL" of the records in the form.

What you need to do is look at Conditional Formatting. This will allow you
to set the color of the Off field based on its value (one default format and
3 other optional formats).

HTH
Dale

This is my first venture down looping through record set and I am not really
sure of how it is done. But here is what I am trying to do. I have a query
where if a condition is me in one of the fields I want the field to backcolor
to turn to Vbred.
I have a query Named, TermType_Counts_Final and within that query I have a
field named OFF that return yes or no.

What I want is if the value is -1 “yesâ€, I want the backdrop to be vbred.
Below is the code I am using and what it is producing is that all values in
the filed “OFF†are coming back with a backcolor of vbred

Am I even on the right track?

Dim db As DAO.Database
Dim rst As DAO.Recordset


Set db = CurrentDb

Set rst = db.OpenRecordset("TermType_Counts_Final", dbOpenDynaset)

Do While Not rst.EOF
If rst![OFF] <> 0 Then 'The real loop exit condition.
Me.OFF.BackColor = vbRed
End If

rst.MoveNext
Loop

Any help would be greatly appreciated

Andy
 
A

AJOLSON

That was the fix. Thanks. Guess I was to eager to use a loop fuction to see
how it works.

Again thanks

Dale_Fye via AccessMonster.com said:
Is this a continuous form? My guess is yes.

In a continuous form, when you set a property of a particular field, it sets
the value of that field (control) for "ALL" of the records in the form.

What you need to do is look at Conditional Formatting. This will allow you
to set the color of the Off field based on its value (one default format and
3 other optional formats).

HTH
Dale

This is my first venture down looping through record set and I am not really
sure of how it is done. But here is what I am trying to do. I have a query
where if a condition is me in one of the fields I want the field to backcolor
to turn to Vbred.
I have a query Named, TermType_Counts_Final and within that query I have a
field named OFF that return yes or no.

What I want is if the value is -1 “yesâ€, I want the backdrop to be vbred.
Below is the code I am using and what it is producing is that all values in
the filed “OFF†are coming back with a backcolor of vbred

Am I even on the right track?

Dim db As DAO.Database
Dim rst As DAO.Recordset


Set db = CurrentDb

Set rst = db.OpenRecordset("TermType_Counts_Final", dbOpenDynaset)

Do While Not rst.EOF
If rst![OFF] <> 0 Then 'The real loop exit condition.
Me.OFF.BackColor = vbRed
End If

rst.MoveNext
Loop

Any help would be greatly appreciated

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top