Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2008, 11:09 AM
Authorized User
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change Textbox Backcolor for certain records only

Private Sub Form_Load()
On Error GoTo Err1
Dim rs As DAO.Recordset

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

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

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


            End If
                rs.MoveNext

        Loop
    End If
    Me.Refresh

Exit_Form_load:
    Exit Sub
Err1:
    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

 
Old April 25th, 2008, 10:32 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
Else
    Me.Machine.ForeColor = vbBlack
    Me.Machine.FontBold = False
End If

Did that help?


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old April 25th, 2008, 10:34 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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
    Else
        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
    Else
        Me!txtPastDue.BorderColor = lngBlack
        Me!txtPastDue.ForeColor = lngBlack
        Me!txtPastDue.BackColor = lngWhite
    End If
End Sub


mmcdonal

Look it up at: http://wrox.books24x7.com
 
Old April 26th, 2008, 03:49 AM
Authorized User
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
 
Old April 26th, 2008, 10:26 AM
Authorized User
 
Join Date: Feb 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?

 
Old April 28th, 2008, 06:28 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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.


mmcdonal

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
changing the backcolor property of the textbox Fehrer Access VBA 9 April 19th, 2016 10:59 AM
change TextBox.BackColor property onFocus event drasko ASP.NET 1.0 and 1.1 Basics 8 January 26th, 2009 12:23 AM
ComboBox BackColor change LoorD C# 4 October 6th, 2005 12:44 AM
can I change the forecolor and backcolor of text saffower VS.NET 2002/2003 4 October 11th, 2004 02:38 PM
Dynamic Backcolor change in VB caltito Access VBA 0 August 22nd, 2004 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.