#1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2007
    Location
    Calgary
    Posts
    18
    Rep Power
    0

    VBA for Visible Property not working as expected


    On the after update function, I have a few statements to show/hide fields based on what the user selects as the document number. When I toggle between the document numbers 12, 12SK, 13, 13SK, 14 and 14SK I can go back and forth and it works great, but the last two in the function (10 & 16B), the visible fields do not turn off, all the fields under this function still show. I added in "If Me.[Document No] <> "10" & "*" Then" after the else statement under the settings and that worked for that one, but even with that under the code for 16B, it still doesn't turn off. Interestingly, which ever statement I have at the end of this function is the one that doesn't work. eg if I move the document no 12 to the end, then the visibility for fields showing for document 12 won't turn off. Another thing is that if I select any other docuement number that I don't have in this code, all the visible fields, including 10 & 16B do turn off. Your help is greatly appreciated!


    Here is the code:


    Private Sub DocumentNo_AfterUpdate()

    If Me.[Document No] Like "13SK" & "*" Then
    Me.AffiliateCompany_Label.Visible = True
    Me.Affiliate_Company.Visible = True
    Me.Registration_Label.Visible = True
    Me.Registration_Type.Visible = True
    Me.LTO_Label.Visible = True
    Me.LTO.Visible = True
    Me.LTO = "SK"
    Else
    Me.AffiliateCompany_Label.Visible = False
    Me.Affiliate_Company.Visible = False
    Me.Registration_Label.Visible = False
    Me.Registration_Type.Visible = False
    Me.LTO = "N/A"
    Me.LTO_Label.Visible = False
    Me.LTO.Visible = False

    If Me.[Document No] Like "13" & "*" Then
    Me.AffiliateCompany_Label.Visible = True
    Me.Affiliate_Company.Visible = True
    Me.Registration_Label.Visible = True
    Me.Registration_Type.Visible = True
    Me.LTO_Label.Visible = True
    Me.LTO.Visible = True
    Else
    Me.AffiliateCompany_Label.Visible = False
    Me.Affiliate_Company.Visible = False
    Me.Registration_Label.Visible = False
    Me.Registration_Type.Visible = False
    Me.LTO_Label.Visible = False
    Me.LTO.Visible = False

    If Me.[Document No] Like "12SK" & "*" Or Me.[Document No] Like "14SK" & "*" Then
    Me.Registration_Label.Visible = True
    Me.Registration_Type.Visible = True
    Me.LTO_Label.Visible = True
    Me.LTO.Visible = True
    Me.LTO = "SK"
    Else
    Me.Registration_Label.Visible = False
    Me.Registration_Type.Visible = False
    Me.LTO_Label.Visible = False
    Me.LTO = "N/A"
    Me.LTO.Visible = False

    If Me.[Document No] Like "12" & "*" Or Me.[Document No] Like "14" & "*" Then
    Me.Registration_Label.Visible = True
    Me.Registration_Type.Visible = True
    Me.LTO_Label.Visible = True
    Me.LTO.Visible = True
    Else
    Me.Registration_Label.Visible = False
    Me.Registration_Type.Visible = False
    Me.LTO_Label.Visible = False
    Me.LTO.Visible = False

    If Me.[Document No] Like "10" & "*" Then
    Me.IOGC_Label.Visible = True
    Me.IOGG_Band.Visible = True
    Else
    If Me.[Document No] <> "10" & "*" Then
    Me.IOGC_Label.Visible = False
    Me.IOGG_Band.Visible = False

    If Me.[Document No] Like "16B-" & "*" Then
    Me.Party1.Visible = True
    Me.Party2.Visible = True
    Me.A_nN_Label.Visible = True
    Me.Party1_Label.Visible = True
    Me.Party2_Label.Visible = True
    Else
    If Me.[Document No] <> "16B-" & "*" Then
    Me.A_nN_Label.Visible = False
    Me.A_nN.Visible = False
    Me.A_nN.Visible = False
    Me.Party1_Label.Visible = False
    Me.Party2_Label.Visible = False
    Me.Party1.Visible = False
    Me.Party2.Visible = False

    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If

    End Sub
  2. #2
  3. Moderator
    ASP Super Genius (4500 - 4999 posts)

    Join Date
    Apr 2009
    Location
    The Great Land
    Posts
    4,620
    Rep Power
    650
    Using wildcard requires LIKE operator.

    Try:

    NOT LIKE "10" & "*"

    MS Access: LIKE Condition (using wildcards) in Access 2003/XP/2000/97
    I like to know if my suggestion helped you. One way to let me know is by clicking star at bottom left corner of post.
    Debug!Debug!Debug!http://www.cpearson.com/excel/debug.htm
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2007
    Location
    Calgary
    Posts
    18
    Rep Power
    0
    Thanks for your suggestion, unfortunately, when using Not Like, I get a Compile Error message and it highlights the work "Like".
  6. #4
  7. Contributing User
    ASP Adventurer (500 - 999 posts)

    Join Date
    Feb 2008
    Location
    Lake County, IL
    Posts
    865
    Rep Power
    152
    Syntax needs to look like this:
    Code:
    If  not Me.[Document No] Like "16B-" & "*" Then
    Alan Sidman
    Office 2010, 2007, 2002

    If I helped you, then click "give rep" button in the lower left corner.

Similar Threads

  1. Visible Property of Label
    By richyrich in forum .NET Development
    Replies: 17
    Last Post: October 11th, 2007, 09:42 AM
  2. Visible property
    By javalsu in forum ASP Development
    Replies: 1
    Last Post: February 8th, 2007, 09:48 AM
  3. RadioButtonList Visible Property
    By jaslar18 in forum ASP Development
    Replies: 2
    Last Post: October 27th, 2006, 01:45 PM
  4. Replies: 2
    Last Post: September 23rd, 2004, 11:54 AM
  5. Allow Edits Property NOT WORKING!
    By black_angel_y2k in forum Microsoft Access Help
    Replies: 3
    Last Post: April 22nd, 2004, 02:21 PM

IMN logo majestic logo threadwatch logo seochat tools logo