If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Changing Text Box BackColor

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Aug 2007
Posts: 6
Changing Text Box BackColor

Hey guys, i got a enquiry here, cant figure it out myself.

I got a textbox field that validates what users input, if the users enters, lets say, less than 10, then the back color of the texfield will turns red, and if the users enter more than 10, it will be reverted back to normal(white background). I wanted the color be be reverted back to normal when the users click to a fresh next record(sort of like clear every fields) and the color will still be red when i previous back the record which fails the validation rule(<10).


Private Sub textbox_AfterUpdate()

if textbox < 10 then
textbox.BackColor = vbRed
else
text box.BackColor = vbWhite
End if

End Sub

Currently i am stuck at when users click a fresh new record, the background is still red in the fresh new record.

Thank you for the patience.
Reply With Quote
  #2 (permalink)  
Old
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 11,002
Would this do the trick? It may need putting on the On Current event.
Code:
If Isnull(textbox.value) Or textbox.value >= 10 Then
 textbox.BackColor = vbWhite
Else
 textbox.BackColor = vbRed
End If
__________________
George
Home | Blog
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Aug 2007
Posts: 6
i tried but it still doesn't work or i did it incorrectly.
Alright here is the exact code

I have 2 declarations at Module

Codes:
Public Const LowerLimit As Integer = 90
Public Const UpperLimit As Integer = 100

'So it means any point of time, my values for the textbox must be from 90 to 100. if not the backcolor will change to red.

At Form Page Level

Codes:

Private Sub Textbox_AfterUpdate()

if Textbox < LowerLimit or Textbox > Upperlimit
Textbox.BackColor = vbRed
Else
Textbox.BackColor = vbWhite
End If
End Sub

So what do i put in form_current as suggested? Thanks again.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: Jun 2007
Location: Maitland NSW,Australia
Posts: 388
How do you navigate between the records?

On the form have two command buttons

One button to add a new record, the other to go to the previous record. Turn off the navigations buttons down at the bottom of the form so that the user can only use the command buttons for navigation.

The Add new record button your code should look like this

Private Sub new_record_Click()
On Error GoTo Err_new_record_Click

DoCmd.GoToRecord , , acNewRec
test_field.BackColor = vbWhite

Exit_new_record_Click:
Exit Sub

Err_new_record_Click:
MsgBox Err.Description
Resume Exit_new_record_Click

End Sub


The Previous record coding will take you to the previous record

Now the On Current event will need to have the following coding
Private Sub Form_Current()
If (test_field < LowerLimit) Or (test_field > UpperLimit) Then
test_field.BackColor = vbRed
Else
test_field.BackColor = vbWhite
End If

End Sub

Your textbox coding will remain the same, I have added some brackets to group the conditions, just a safety feature that I use.

Private Sub Textbox_AfterUpdate()

if (Textbox < LowerLimit) or (Textbox > Upperlimit) then
Textbox.BackColor = vbRed
Else
Textbox.BackColor = vbWhite
End If
End Sub
__________________
Poppa Smurf
allanmurphy47@gmail.com
Reply With Quote
  #5 (permalink)  
Old
Moderator
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 2,477
Are we dealing with Access 97 here? I don't see anything here to that effect. If not, why not simply use Conditional Formatting?
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2003/2007
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Aug 2007
Posts: 6
I tried but it cant work. I am using Access 2003 here.

Last edited by DbFanatics; 08-19-07 at 08:28.
Reply With Quote
  #7 (permalink)  
Old
Moderator
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 2,477
If you're using ACC2003 then use the built in Conditional Formatting!

In Design View select the textbox.

On the Menu Bar goto Format - Conditional Formatting

For Condition1:
Field Value Is Less Than 90
Click on the bucket icon (BackFill) and click on red.

Click on Add>>

For Condition2:
Field Value Is Greater Than 100
Click on the bucket (BackFill) and click on red.

Click on OK

You're done!

Linq
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2003/2007
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
Join Date: Aug 2007
Posts: 6
Yes! Thats exactly what i want, i will navigate more on the menu-bar functions. Thank you Missinglinq!!!
Reply With Quote
  #9 (permalink)  
Old
Moderator
 
Join Date: Jun 2005
Location: Richmond, Virginia USA
Posts: 2,477
Glad you got it working!

Linq
__________________
Hope this helps!

The Devil's in the Details!!

All posts/responses based on Access 2003/2007
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 On
Pingbacks are On
Refbacks are On