Results 1 to 4 of 4
  1. #1
    laavista is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2010
    Posts
    42

    Change font color of text box, based on variable

    I have a text box on a form and would like to change the forecolor to black or white (so the text is invisible) based on a variable.

    I tried using the conditional formatting feature.


    If MyVar = "Y" then do the conditional formatting.
    In conditional formatting , I tried
    1) Expression is MyVar = "Y" (it interpreted this as "MyVar" = "Y")
    2) Expression is '" & MyVar & "' = "Y" (didn't work)

    I also tried putting it in the code. On click of a different button, I tried:
    1) txtMyTextBoox.ForeColor = RGB(255, 255, 255) (didn't work)
    2) txtMyTextBox.ForeColor = vbBlack (didn't work)


    Any suggestions?



  2. #2
    laavista is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2010
    Posts
    42

    Solved

    I figured it out.

    A public variable cannot be used in a form "as is". You have to call it from a function (.e.g., = getMyVariable).

    Once I did this, the .forecolor worked with my text box.

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2007
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm glad you got your code working but what you state about public variables is not true.

  4. #4
    laavista is offline Advanced Beginner
    Windows Vista Access 2007
    Join Date
    Jun 2010
    Posts
    42

    thanks

    Thanks for the info on public variables. I read that on the internet somewhere. Should have checked it out before posting that!

    At least I did get the code working.

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

Similar Threads

  1. Change font color in Query
    By Brian62 in forum Queries
    Replies: 2
    Last Post: 01-10-2013, 09:14 PM
  2. Changing font color based on criteria
    By Pattie Weaver in forum Reports
    Replies: 5
    Last Post: 11-02-2010, 03:38 PM
  3. Change color font when updating data?
    By Mike1379 in forum Reports
    Replies: 3
    Last Post: 05-17-2010, 08:00 AM
  4. Change as per condition font color
    By miziri in forum Programming
    Replies: 1
    Last Post: 08-20-2009, 04:23 AM
  5. Color/font change in subform
    By AndyKim in forum Forms
    Replies: 9
    Last Post: 06-24-2009, 04:34 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