Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 24th, 2008, 11:09 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old April 25th, 2008, 10:32 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #3 (permalink)  
Old April 25th, 2008, 10:34 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
  #4 (permalink)  
Old April 26th, 2008, 03:49 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
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
Reply With Quote
  #5 (permalink)  
Old April 26th, 2008, 10:26 AM
Authorized User
 
Join Date: Feb 2008
Location: , , .
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?

Reply With Quote
  #6 (permalink)  
Old April 28th, 2008, 06:28 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 50%
Activity: 50% Activity: 50% Activity: 50%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
change TextBox.BackColor property onFocus event drasko ASP.NET 1.0 and 1.1 Basics 8 January 25th, 2009 11:23 PM
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
changing the backcolor property of the textbox Fehrer Access VBA 8 December 29th, 2003 01:23 PM



All times are GMT -4. The time now is 11:44 PM.


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