Results 1 to 5 of 5
  1. #1
    adeebarsad is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    15

    Hide/Show Textbox when it is null/not null(Access Form)

    Hi everyone!
    I am creating 2 forms. One form when you click a specific test, it will open another form which shows all the information about the test. Some tests does not have any information/not available so it will just show an empty textbox when there is no data. I want the empty field/textbox to be hidden if there is no data/null and only to be shown if it is not null.


    I've tried using the After_Update event on the textbox but can't get it work:
    If Me.txt42 = "" then
    Me.txt42.visible = true
    else
    me.txt42.visible = false
    End if


  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    If isnull(me.txt42) = true then

    You may also have to use me.refresh to refresh the record source.


    Sent from my iPhone using Tapatalk

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    assuming this is not a continuous form, try

    me.txt42.visible=not isnull(me.text42)

  4. #4
    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
    There's a several problems with your approach.

    If Me.txt42 = "" Then

    only checks for txt42 being populated with a Zero-Length String...while 'empty' Controls in Access usually are Null...not populated with ZLSs.

    Andy49's and Ajax's suggestion of using IsNull() is a better approach.

    Even better is something like this

    If Nz(Me.txt42, "") = "" Then

    which checks for both ZLSs and Nulls!

    The After_Update event on the textbox will only fire if data is entered into the Control...or deleted from the Control...and will only be Null if data is entered and then deleted. If the Control is just ignored...never entered...it will also not fire! You can only reliably check whether a Control is populated or not using the Form_BeforeUpdate event.

    Quote Originally Posted by adeebarsad View Post
    ...I've tried using the After_Update event on the textbox
    This would suggest that the Form is being used for Data Entry, which begs the question...how can you later enter data in this Control, if need be (if it later becomes available) if it is no longer Visible?

    Linq ;0)>

    data
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    adeebarsad is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    15
    Thank you all for the response! I got it work already. Should have used On Current Event instead of After_Update. That was my mistake.

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

Similar Threads

  1. Replies: 7
    Last Post: 11-07-2016, 09:24 AM
  2. Replies: 1
    Last Post: 03-12-2014, 03:13 AM
  3. Replies: 7
    Last Post: 02-20-2014, 01:24 PM
  4. Replies: 3
    Last Post: 07-25-2013, 05:19 PM
  5. Replies: 5
    Last Post: 05-22-2012, 08:06 AM

Tags for this Thread

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