Results 1 to 15 of 15
  1. #1
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24

    Hiding Text Box and Label on Current Event

    I am tryingto use the On Current Event to hide a text box and label using the expressionbelow:



    =IIf([ATStatus]= "Conducting Less Than 15 Days of AT (Remarks Required with total# days to be utilized)",Unit Reported # Days to beUsed].[Visible]=True,[Unit Reported # Days to be Used].[Visible]=False)

    Am I usingthe wrong method to hide the text box if the other text box does not containthe specific text or is there a problem with my IIf statement?


  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,750
    Hi

    This section is wrong:-

    Unit Reported # Days to beUsed].[Visible]=True,

    It should be:-

    [Unit Reported # Days to beUsed].[Visible]=True,

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    For the record it's best not to use spaces or special characters for object names, objects being text boxes, labels, form names, tables, queries, fields, etc. Only use spaces and special characters in labels and/or for presentation purposes.

    I would use the on current event and a VBA routine. It would simply be something like:

    if Me.atstatus = "..." then
    Me.textbox_name.visible = false
    Else
    Me.textbox_name.visible = true
    End if

  4. #4
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    I corrected that, thank you. However it still does not do the trick.

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    I'm not sure that you can make those property changes from an Iif expression. Give it a try from a VBA sub like I posted in #3, that should do the trick. You'll delete the whole expression from the OnCurrent event properties, then click the '...' button and choose 'Code Builder'

    As long as the label is linked to the textbox it should automatically show/hide with the textbox.

  6. #6
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    I have not done much in VBA and am still fumbling with it This I what I tried....



    Option Compare Database


    If Me.[AT Status] = "Conducting Less Than 15 Days of AT (Remarks Required with total # days to be utilized" Then
    Me.textbox_ [Unit Reported # Days to be Used].Visible = True
    Else
    Me.textbox_ [Unit Reported # Days to be Used].Visible = False
    End If
    Private Sub Form_Current()
    End Sub


    AND



    Option Compare Database
    Private Sub Form_Current()
    If Me.[AT Status] = "Conducting Less Than 15 Days of AT (Remarks Required with total # days to be utilized" Then
    Me.textbox_ [Unit Reported # Days to be Used].Visible = True
    Else
    Me.textbox_ [Unit Reported # Days to be Used].Visible = False
    End If
    End Sub

  7. #7
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    That's a good start. The second version is almost right. Try this, delete the textbox_ part so it looks like this Me.[Unit Reported # Days to be Used].Visible = False

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    or slightly more simple

    Code:
    Option Compare Database
    
    Private Sub Form_Current()
    
            [Unit Reported # Days to be Used].Visible = Me.[AT Status] = "Conducting Less Than 15 Days of AT (Remarks Required with total # days to be utilized"
    
    End Sub
    I note in your other thread that you had

    [ATStatus]="Conducting Less Than 15 Days of AT (Remarks Required with total #days to be utilized)"

    looks to me like you have a typo with missing spaces and brackets

    you might want to consider have a table with a PK and description for your status's

  9. #9
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    This worked and I added the same using the label name in the same code.

  10. #10
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    While this did work to make it invisible it throws a debug error when [AT Status] Is Null. What is the added code to fix that?

  11. #11
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,165
    Code:
    if isnull( Me.[AT Status] ) then
       'do something
    
    elseif Me.[AT Status] = "..." then
         'show text box code here
    
    else
         'hide text box code here
    
    end if

  12. #12
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    When I try it that way it tells me there is an error with this part "Private Sub Form_Current()"


    Private Sub Form_Current()

    If IsNull(Me.[AT Status]) Then
    Me.[Unit Reported # Days to be Used].Visible = False
    ElseIf Me.[AT Status] = "Conducting Less Than 15 Days of AT (Remarks Required with total # days to be utilized)" Then
    Me.[Unit Reported # Days to be Used].Visible = True
    Else

    Me.[Unit Reported # Days to be Used].Visible = False
    End If

  13. #13
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    when [AT Status] Is Null
    Code:
    Option Compare Database
    
    Private Sub Form_Current()
    
            [Unit Reported # Days to be Used].Visible = nz(Me.[AT Status],"") = "Conducting Less Than 15 Days of AT (Remarks Required with total # days to be utilized"
    
    End Sub

  14. #14
    sgtclark is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2020
    Posts
    24
    Thank you, worked like a charm. I did not realize that the Nz function worked with none numeric values. Thanks for the education.

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,842
    nz works for nulls - strings are often zero length ("") which are not null so nz(Me.[AT Status],"") works for both scenarios

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

Similar Threads

  1. hiding a label in a report
    By angie in forum Access
    Replies: 13
    Last Post: 04-09-2018, 12:15 PM
  2. On Current Event Question
    By JeRz in forum Programming
    Replies: 2
    Last Post: 10-19-2016, 09:41 AM
  3. Event Timing with Hiding/Unhiding Objects
    By mcfischer91 in forum Programming
    Replies: 4
    Last Post: 07-25-2014, 01:35 PM
  4. cbo Issue and On Current Event
    By buckwheat in forum Access
    Replies: 10
    Last Post: 08-29-2013, 11:39 AM
  5. Replies: 5
    Last Post: 04-24-2013, 08:50 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