Formatting using Details On Format Event

P

Phyxious

I am using the On Format Event for the Details section in a report, too which
I want it to format the textboxes contained there based on a certain
condition. Everything seems to work fine but instead of it formating each
line individually, it formats everything based on the last condition. Would
anyone know how I would go about doing it, so each line will be different? My
code is as follows:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim rs As New ADODB.Recordset
Dim db As New ADODB.Connection
Dim i As Integer
Dim SQL As String

SQL = "SELECT something FROM somewhere"
Set db = Application.CurrentProject.Connection
rs.Open SQL, db, adOpenDynamic, adLockOptimistic

rs.MoveFirst
Do While Not rs.EOF
If (rs.Fields(i).Value <= 0) Then
Me.textbox1.ForeColor = 238
Me.textbox2.ForeColor = 238
Me.textbox3.ForeColor = 238
Me.textbox4.ForeColor = 238
Me.textbox5.ForeColor = 238
Me.textbox6.ForeColor = 238
Me.textbox7.ForeColor = 238
Me.textbox8.ForeColor = 238
Me.textbox9.ForeColor = 238
Me.textbox10.ForeColor = 238
ElseIf ((rs.Fields(i).Value >= 1) Or (rs.Fields(i).Value = 365)) Then
Me.textbox1.ForeColor = 11823615
Me.textbox2.ForeColor = 11823615
Me.textbox3.ForeColor = 11823615
Me.textbox4.ForeColor = 11823615
Me.textbox5.ForeColor = 11823615
Me.textbox6.ForeColor = 11823615
Me.textbox7.ForeColor = 11823615
Me.textbox8.ForeColor = 11823615
Me.textbox9.ForeColor = 11823615
Me.textbox10.ForeColor = 11823615
ElseIf ((rs.Fields(i).Value >= 366) Or (rs.Fields(i).Value = 730)) Then
Me.textbox1.ForeColor = 16711680
Me.textbox2.ForeColor = 16711680
Me.textbox3.ForeColor = 16711680
Me.textbox4.ForeColor = 16711680
Me.textbox5.ForeColor = 16711680
Me.textbox6.ForeColor = 16711680
Me.textbox7.ForeColor = 16711680
Me.textbox8.ForeColor = 16711680
Me.textbox9.ForeColor = 16711680
Me.textbox10.ForeColor = 16711680
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
End Sub

Like I said everything works like it suppose to except rather then each line
being formated individually, it is formating every line based on the last
condition that was met. Any help is greatly appriciated. Thank you.
 

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