p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/)
-   Access VBA (http://p2p.wrox.com/access-vba-80/)
-   -   Change Textbox Backcolor for certain records only (http://p2p.wrox.com/access-vba/67643-change-textbox-backcolor-certain-records-only.html)

camehere April 24th, 2008 12:09 PM

Change Textbox Backcolor for certain records only
Private Sub Form_Load()
On Error GoTo Err1
Dim rs As DAO.Recordset

    Set rs = Me.RecordsetClone
    If rs.RecordCount > 0 Then
        Do Until rs.EOF

            If ((Month(Now) = 4) And (rs!Apr = True)) Then

                   rs!Machine.BackColor = 13500152 '(How?)

            End If

    End If

    Exit Sub
    MsgBox Err.Description
    Resume Exit_Form_load
End Sub
__________________________________________________ _____________
I aim to change textbox backcolor of a field "Machine" for certain records which have fulfilled some criteria

Set the color of the textbox of field “machine” of records which shows its maintenance schedule is in april.Only those records which has schedule in april will have its corresponding record textbox “machine” set to yellow. But,I typed rs!Machine.Backcolor = 13500152, & error.How should code be?

tried Me.Machine.Backcolor = 13500152 & ended up havin all textboxes “machine” on the form set to yellow.But this is not i want as only some records should have textbox backcolor to yellow. Or any other method to achieve this?

Please help... Thank you..:D

mmcdonal April 25th, 2008 11:32 AM

You are using the wrong event. Use the Detail section's On Format event for this. I use the following code to change the Font color. I am note sure about the text box color.

In the On Format event:

If ((Month(Now) = 4) And (Me.Apr = True)) Then
    Me.Machine.ForeColor = vbRed
    Me.Machine.FontBold = True
    Me.Machine.ForeColor = vbBlack
    Me.Machine.FontBold = False
End If

Did that help?


Look it up at: http://wrox.books24x7.com

mmcdonal April 25th, 2008 11:34 AM

Here is the code form Access help on BackColor for changing the backcolor on a form's text field on the On Current event:

Sub Form_Current()
    Dim curAmntDue As Currency, lngBlack As Long
    Dim lngRed As Long, lngYellow As Long, lngWhite As Long

    If Not IsNull(Me!txtPastDue.Value) Then
        curAmntDue = Me!txtPastDue.Value
        Exit Sub
    End If
    lngRed = RGB(255, 0, 0)
    lngBlack = RGB(0, 0, 0)
    lngYellow = RGB(255, 255, 0)
    lngWhite = RGB(255, 255, 255)
    If curAmntDue > 100 Then
        Me!txtPastDue.BorderColor = lngRed
        Me!txtPastDue.ForeColor = lngRed
        Me!txtPastDue.BackColor = lngYellow
        Me!txtPastDue.BorderColor = lngBlack
        Me!txtPastDue.ForeColor = lngBlack
        Me!txtPastDue.BackColor = lngWhite
    End If
End Sub


Look it up at: http://wrox.books24x7.com

camehere April 26th, 2008 04:49 AM

Thanks for your reply. But I still have problems:

On Event of Detail, I only see On Click, On Double Click, On Mouse Up, On mouse move, on mouse up. There is no On Format for me to choose from. How do I create this event? I am using MS Access 2000

Btw, this is a continuous form

camehere April 26th, 2008 11:26 AM

hey I searched past threads and found out that "on format" is used in reports only. Is there any other method to be used on forms?

mmcdonal April 28th, 2008 07:28 AM

You are correct. I was thinking this was a report. Continuous forms are impossible to format per record. You can only format once, and every record will maintain that format. So no chance of using this method on a continuous form.


Look it up at: http://wrox.books24x7.com

All times are GMT -4. The time now is 10:18 AM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.