Results 1 to 7 of 7
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    change text box color if its null


    What code should i write in vb if text field is null then the text box background color to change into red and if its not null then the background color is yellow.

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    What code have you already tried?

  3. #3
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,800
    Did you consider conditional formatting instead of code?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  4. #4
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    how can i do that? as i want to highlight if the text box field is null

  5. #5
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,976
    Set the default background colour to red.
    Use conditional formatting so if field value <>"" (or is not null) the colour is yellow
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  6. #6
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Thank You

    I used

    [NIC No]<>""

    This worked as required

  7. #7
    ghiasibrahim is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2018
    Location
    Damascus
    Posts
    14
    if your textbox name is for example (txt1) the code would be

    if txt1.value = " " then
    txt1.backcolor= vbred
    else
    txt1.backcolor = vbyellow
    end if

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

Similar Threads

  1. Change Text color and/or background color
    By Thompyt in forum Reports
    Replies: 2
    Last Post: 02-23-2017, 07:08 PM
  2. Text box change color
    By Ray67 in forum Forms
    Replies: 14
    Last Post: 11-19-2012, 04:06 PM
  3. Replies: 5
    Last Post: 09-18-2012, 12:39 PM
  4. Using an event to change color of text.
    By michaeljohnh in forum Programming
    Replies: 3
    Last Post: 08-30-2010, 12:30 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