EOF, row color change

A

AlexD

How could highlight the matched row with red to alert user
and how I could avoid (associated with EOF) an error
message "no current record"?

With rstRecycled

If .RecordCount <> 0 Then
.MoveFirst

Do While Not .EOF
.MoveNext ' <need to avoid "no current
record">

If ![ToBeUsedDate] > Date - 3 Then

???????????????????????
' highlight the row with a red color

End If

Loop
End If
End With

rstRecycled.Close
dbs.Close
 
C

Chris Nebinger

If you have 10 real records, and are sitting on the last
one, you can still .MoveNext. Now you will be sitting on
EOF.

The reason you get a No Current Record error is that you
move to the next record, the EOF, and then try and read a
field value. Change the location of the .MoveNext to
right before the loop.


Now, as far as what you are trying to do, I would assume
that you are in a form, and want to highlight the record
if the to be used date is prior than 3 days ago? What
version of Access are you using? If it is Access 2000 or
greater, look into Conditional Formating. Otherwise,

Private Sub Form_Current()
If Me.ToBeUsedDate > Date() - 3 Then
Me.ToBeUsedDate.BackColor = vbRed
Else
Me.ToBeUsedDate.BackColor = vbWhite
End If
End Sub


Chris Nebinger
 
A

Alan Fisher

-----Original Message-----
How could highlight the matched row with red to alert user
and how I could avoid (associated with EOF) an error
message "no current record"?

With rstRecycled

If .RecordCount <> 0 Then
.MoveFirst

Do While Not .EOF
.MoveNext ' <need to avoid "no current
record">

If ![ToBeUsedDate] > Date - 3 Then

???????????????????????
' highlight the row with a red color

End If

Loop
End If
End With

rstRecycled.Close
dbs.Close
.
I use the Conditional Formatting to make records
different colors. In the forms design mode, select the
field where the ToBeUsedDate is then look under the Format
menu and select Conditional Formatting. You can then
select the Equals criteria and put [ToBeUsedDate] > Date -
3 and then you can select a font color for those records
that meet the criteria. It's a lot easier than trying to
code it.
 
A

AlexD

Thanks, Chris.

I've already tried to do the same for the color (but, by
using load instead of current).
The problem is I'm trying to use the form in datasheet
view.
Could you please advise whether it's possible to change
the color in this case.


-----Original Message-----
If you have 10 real records, and are sitting on the last
one, you can still .MoveNext. Now you will be sitting on
EOF.

The reason you get a No Current Record error is that you
move to the next record, the EOF, and then try and read a
field value. Change the location of the .MoveNext to
right before the loop.


Now, as far as what you are trying to do, I would assume
that you are in a form, and want to highlight the record
if the to be used date is prior than 3 days ago? What
version of Access are you using? If it is Access 2000 or
greater, look into Conditional Formating. Otherwise,

Private Sub Form_Current()
If Me.ToBeUsedDate > Date() - 3 Then
Me.ToBeUsedDate.BackColor = vbRed
Else
Me.ToBeUsedDate.BackColor = vbWhite
End If
End Sub


Chris Nebinger



-----Original Message-----
How could highlight the matched row with red to alert user
and how I could avoid (associated with EOF) an error
message "no current record"?

With rstRecycled

If .RecordCount <> 0 Then
.MoveFirst

Do While Not .EOF
.MoveNext ' <need to avoid "no current
record">

If ![ToBeUsedDate] > Date - 3 Then

???????????????????????
' highlight the row with a red color

End If

Loop
End If
End With

rstRecycled.Close
dbs.Close
.
.
 
A

AlexD

Thanks, Alan.

How about the case if the form is in the datasheet view?
-----Original Message-----
-----Original Message-----
How could highlight the matched row with red to alert user
and how I could avoid (associated with EOF) an error
message "no current record"?

With rstRecycled

If .RecordCount <> 0 Then
.MoveFirst

Do While Not .EOF
.MoveNext ' <need to avoid "no current
record">

If ![ToBeUsedDate] > Date - 3 Then

???????????????????????
' highlight the row with a red color

End If

Loop
End If
End With

rstRecycled.Close
dbs.Close
.
I use the Conditional Formatting to make records
different colors. In the forms design mode, select the
field where the ToBeUsedDate is then look under the Format
menu and select Conditional Formatting. You can then
select the Equals criteria and put [ToBeUsedDate] > Date -
 
C

Chris Nebinger

What version of Access are you using? Can you use
conditional formatting?

If so, then this is alot easier.

In Design View, select all the controls on the form. Then
click on Format, Conditional Formatting.

Now, change on "Condition 1" from Field Value is to
Expression Is. For the expression, use [ToBeUsedDate] >
Date - 3

Now, adjust the back color, font color, etc. as you see
fit.

Open the form and see if it works.


Chris Nebinger

-----Original Message-----
Thanks, Chris.

I've already tried to do the same for the color (but, by
using load instead of current).
The problem is I'm trying to use the form in datasheet
view.
Could you please advise whether it's possible to change
the color in this case.


-----Original Message-----
If you have 10 real records, and are sitting on the last
one, you can still .MoveNext. Now you will be sitting on
EOF.

The reason you get a No Current Record error is that you
move to the next record, the EOF, and then try and read a
field value. Change the location of the .MoveNext to
right before the loop.


Now, as far as what you are trying to do, I would assume
that you are in a form, and want to highlight the record
if the to be used date is prior than 3 days ago? What
version of Access are you using? If it is Access 2000 or
greater, look into Conditional Formating. Otherwise,

Private Sub Form_Current()
If Me.ToBeUsedDate > Date() - 3 Then
Me.ToBeUsedDate.BackColor = vbRed
Else
Me.ToBeUsedDate.BackColor = vbWhite
End If
End Sub


Chris Nebinger



-----Original Message-----
How could highlight the matched row with red to alert user
and how I could avoid (associated with EOF) an error
message "no current record"?

With rstRecycled

If .RecordCount <> 0 Then
.MoveFirst

Do While Not .EOF
.MoveNext ' <need to avoid "no current
record">

If ![ToBeUsedDate] > Date - 3 Then

???????????????????????
' highlight the row with a red color

End If

Loop
End If
End With

rstRecycled.Close
dbs.Close
.
.
.
 
A

AlexD

Thanks, Chris.
It's working perfectly.

Alex
-----Original Message-----
What version of Access are you using? Can you use
conditional formatting?

If so, then this is alot easier.

In Design View, select all the controls on the form. Then
click on Format, Conditional Formatting.

Now, change on "Condition 1" from Field Value is to
Expression Is. For the expression, use [ToBeUsedDate] >
Date - 3

Now, adjust the back color, font color, etc. as you see
fit.

Open the form and see if it works.


Chris Nebinger

-----Original Message-----
Thanks, Chris.

I've already tried to do the same for the color (but, by
using load instead of current).
The problem is I'm trying to use the form in datasheet
view.
Could you please advise whether it's possible to change
the color in this case.


-----Original Message-----
If you have 10 real records, and are sitting on the last
one, you can still .MoveNext. Now you will be sitting on
EOF.

The reason you get a No Current Record error is that you
move to the next record, the EOF, and then try and read a
field value. Change the location of the .MoveNext to
right before the loop.


Now, as far as what you are trying to do, I would assume
that you are in a form, and want to highlight the record
if the to be used date is prior than 3 days ago? What
version of Access are you using? If it is Access 2000 or
greater, look into Conditional Formating. Otherwise,

Private Sub Form_Current()
If Me.ToBeUsedDate > Date() - 3 Then
Me.ToBeUsedDate.BackColor = vbRed
Else
Me.ToBeUsedDate.BackColor = vbWhite
End If
End Sub


Chris Nebinger




-----Original Message-----
How could highlight the matched row with red to alert
user
and how I could avoid (associated with EOF) an error
message "no current record"?

With rstRecycled

If .RecordCount <> 0 Then
.MoveFirst

Do While Not .EOF
.MoveNext ' <need to avoid "no current
record">

If ![ToBeUsedDate] > Date - 3 Then

???????????????????????
' highlight the row with a red color

End If

Loop
End If
End With

rstRecycled.Close
dbs.Close
.

.
.
.
 

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