Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

Formatting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry G. - 15 Mar 2005 19:37 GMT
I posted this question in the general Access area earlier, but maybe I can
get a better answer in this forum.

I am trying to format the back color of a text box in a form, based on the
value in another text box. If this was Excel it would be easier to use
conditional formatting based onthe value of the second cell, but in A2000
there is no way that I am aware of, other than writing some code. So here is
what I have so far (that does not work):

Dim CAPR As String

   CAPR = Text50.Text
   If CAPR = "1" Then
       txtSiteNum.BackColor = vbBlue
       txtSiteNum.ForeColor = vbWhite
       Else
       txtSiteNum.BackColor = vbWhite
       txtSiteNum.ForeColor = vbBlack
   End If
   
I am not sure where there error lies or if this will even work. Any help
would be greatly appreciated.

Larry
Rick B - 15 Mar 2005 19:50 GMT
Please see your other post.  Use conditional formatting.  You can evaluate
any condition expression.  Not just the current field.

Rick B

> I posted this question in the general Access area earlier, but maybe I can
> get a better answer in this forum.
[quoted text clipped - 20 lines]
>
> Larry
fredg - 15 Mar 2005 20:01 GMT
> I posted this question in the general Access area earlier, but maybe I can
> get a better answer in this forum.
>
> I am trying to format the back color of a text box in a form, based on the
> value in another text box. If this was Excel it would be easier to use
> conditional formatting based onthe value of the second cell,

Regarding...
>>>> but in A2000
> there is no way that I am aware of, other than writing some code.

Who says?
Click on the Control (in design View) and select
Format + Conditional Formatting. See below.

> So here is
> what I have so far (that does not work):
[quoted text clipped - 10 lines]
>     End If
>    
In Access, you would not reference a control's Text property, it would
be the control's Value property. Since the Value property is the
control's default property you do not need to explicitly state it.
You could re-write the above code like this:

Dim CAPR As String

    CAPR = Text50
    If CAPR = "1" Then
           txtSiteNum.BackColor = vbBlue
           txtSiteNum.ForeColor = vbWhite
        Else
           txtSiteNum.BackColor = vbWhite
           txtSiteNum.ForeColor = vbBlack
    End If

You can even shorten the above code:
No need to Dim CAPR as long as Text50 is a control on this form.

txtSiteNum.BackColor = Text50 = 1
txtSiteNum.ForeColor = Text50 = 1

You would place the above code in BOTH the Form's Current event as
well as the Text50 AfterUpdate event.

This will work in Single View Form View.
If you are using Continuous View Form, use Conditional Formatting.

In Design View, select [tstSiteNum].
Click Format + Conditional Formatting
Set the Condition1 to
Expression Is
In the next box write
[Text50] = 1
Set the Condition forecolor and backcolor as wanted.

> I am not sure where there error lies or if this will even work. Any help
> would be greatly appreciated.
>
> Larry

Signature

Fred
Please only reply to this newsgroup.
I do not reply to personal email.

Ron Kunce - 15 Mar 2005 20:15 GMT
Text50 appears to be a label type control, in which case you should be using
Text50.caption.  There is no Text property for a label.
In fact, you could save a little memory by getting rid of the variable CAPR
and using a direct call

If Text50.caption = "1" then . . .
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.