Results 1 to 8 of 8
  1. #1
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25

    Changing Forecolor on form

    Good Morning Everyone,

    I am a beginners level at best and I am trying to make a loop where the font colors on a form will be certain colors when loading based on a condition of whether the field 'ContrName(X)' is empty or has text. Most of my fields are categorized by the same name with a different number to distinguish between them. I have evolved into a complicated mess and it still states it can't find the fields even though when you do a watch of the variables it states the field name perfectly. I know most of this in the programming is probably unnecessary but I was trying to help the computer find these fields which it will not find even when I put the horse in the water. This computer is more stubborn than me and that is saying something.....does anyone see why it cannot find these fields?



    Thanks for this site and any help somebody could offer,
    Dave



    Private Sub Form_Load()
    Dim X As Integer
    Dim S As String
    Dim T As String
    Dim U As String
    Dim V As String

    For X = 1 To 10
    S = "ContrName" & CStr(X)
    T = "Qty" & CStr(X)
    U = "UnitCost" & CStr(X)
    V = "calLabor" & CStr(X)

    If IsNull(S) Then
    Me![T].ForeColor = RGB(230, 237, 215)
    Me![U].ForeColor = RGB(230, 237, 215)
    Me![V].ForeColor = RGB(230, 237, 215)
    Else
    Me![T].ForeColor = RGB(186, 20, 25)
    Me![U].ForeColor = RGB(186, 20, 25)
    Me![V].ForeColor = RGB(186, 20, 25)
    End If
    Next X
    End Sub

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742

  3. #3
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25
    Thank you for your response! I have been using the conditional formatting but there are too many fields and I was looking for a better way. It doesn't seem like it should be this hard but I have been working with this on and off for several weeks. I would eventually like to get rid of all the conditional formatting and replace it with code if I can at some point get this to work. Thanks again for your assistance. Dave

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    Can you post a copy of your database? zip it

  5. #5
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25
    I wish I could post it but I think I have too much personal information from many customers, addresses, phone numbers etc to do that.

    I have the code listed above in the form load-event property and maybe that isn't where it should be....or maybe it has something to do with the Private vs Public declaration at the beginning of the sub. I think I have a small understanding of that but I am not confident with it for sure. Anyway, if I can figure out where I am making a mistake with the above code, I would like to have it be a function to call on with all the applicable forms. It was just a thought but I do tend to get ahead of myself at times!

    Thanks again!

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,742
    You could try:

    -copy and paste the same code into the for CurrentEvent
    OR
    - make a copy of the database
    - in the copy remove most of the Customers
    - change some names to Porky Pig, Donald Duck, Joe Blow etc
    - change some personal data;;
    all we need is enough to show the issue with the form.

  7. #7
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    It has to be in the Form_Current event, as orange suggested. In the OnOpen or OnLoad event the ForeColor for all Records will be formatted according to the state of ContrName in the first Record displayed on opening!

    BTW, this isn't hard to do for multiple Controls, whether for two or thirty Controls!

    In Form Design View

    1. Press and hold down the <Shift> Key
    2. Click on each Control you want to Format to select it
    3. Go to Conditional on the Ribbon
    4. Under Condition1 use the dropdown to select Expression Is
    5. In the condition box enter IsNull([YourControlName])
    6. Click on the ForeColor Icon and select the desired color
    7. Click on OK

    replacing YourControlName with the actual name all of this is based on!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  8. #8
    dvgef2 is offline Novice
    Windows 8 Access 2013
    Join Date
    Mar 2013
    Posts
    25
    Ok, I put the code in the Current Event but it still can't find the field. It is so odd to me but I guess there is a reason. Anyway, I think this is more personal than anything else now because I have been trying to figure it out for so long. The code does not seem all that complicated but every time I try something that I think I should be able to do, Access has other plans. I guess it knows me better than I know myself.

    By the way, I thought I tried to do multiple fields at a time with the Conditional Formatting but it would not list the 'Conditional Formatting' option when I right clicked after selecting all the text boxes. I must have to get to it under one of the sub titles, I did not check that.

    Thank you so much for your assistance!
    Dave






    [QUOTE=Missinglinq;289577]It has to be in the Form_Current event, as orange suggested. In the OnOpen or OnLoad event the ForeColor for all Records will be formatted according to the state of ContrName in the first Record displayed on opening!

    BTW, this isn't hard to do for multiple Controls, whether for two or thirty Controls!

    In Form Design View

    1. Press and hold down the <Shift> Key
    2. Click on each Control you want to Format to select it
    3. Go to Conditional on the Ribbon
    4. Under Condition1 use the dropdown to select Expression Is
    5. In the condition box enter IsNull([YourControlName])
    6. Click on the ForeColor Icon and select the desired color
    7. Click on OK

    replacing YourControlName with the actual name all of this is based on!

    Linq ;0)>

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Label.Forecolor
    By SSgtBarry in forum Access
    Replies: 5
    Last Post: 08-21-2014, 03:59 PM
  2. Replies: 1
    Last Post: 06-18-2013, 12:23 PM
  3. Replies: 1
    Last Post: 02-29-2012, 09:38 AM
  4. Replies: 2
    Last Post: 10-19-2011, 03:21 AM
  5. Replies: 1
    Last Post: 08-19-2011, 02:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums