Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2009
    Posts
    39

    Question Unanswered: If Statement for Visible/Non-Visible Fields

    Instead of continually beating my head against the wall, I thought I'd ask you lovely folks for some assistance. I have this form in which I would like several fields to be "not visible" based on an entry in a text box. I have done this with great success for combo boxes in the past, but this text box is throwing me for a loop. If an entry has the word "incident" or "card", I need other fields to disappear. This is what I wrote in VBA on the AfterUpdate of the text box:

    If Me.[Card VIN] = "*CARD*" Then
    Me.X_NUMBER.Visible = False
    Me.LICENSE.Visible = False
    Me.YEAR.Visible = False
    Me.MAKE.Visible = False
    Me.MODEL.Visible = False
    Me.VEH_TYPE.Visible = False
    Else
    Me.X_NUMBER.Visible = True
    Me.LICENSE.Visible = True
    Me.YEAR.Visible = True
    Me.MAKE.Visible = True
    Me.MODEL.Visible = True
    Me.VEH_TYPE.Visible = True
    End If

    That didn't work, so I tried:

    If (Left(Me.Card_VIN, 5) = "incin") Or (Left(Me.Card_VIN, 4) = "card") Then
    Me.X_NUMBER.Visible = False
    Else
    Me.X_NUMBER.Visible = True
    End If

    (I just did the one field this time around until I can figure out the exact wording). I still get a "type mismatch" error. I know that I need to put the code in the Form's On Current, as well as the text box's After Update, but I am not well-versed in VBA so I am at a loss as to how to fix this.

    I've done this before:

    Me.PILOT.Visible = (Left(Me.VEH_TYPE, 11) = "fire engine")

    And I've done:

    If Me.STATUS = "LOAN" Then
    Me.cboUNIT_LOANED.Visible = True
    Me.tbxLOAN_START.Visible = True
    Me.tbxLOAN_END.Visible = True
    Else
    Me.cboUNIT_LOANED.Visible = False
    Me.tbxLOAN_START.Visible = False
    Me.tbxLOAN_END.Visible = False
    End If

    And they work great. I just don't know how to write the opposite of the first one or include "Left" in the second one. Any assistance would be greatly appreciated!!!

    Thanks!
    Last edited by SRR; 01-14-11 at 13:41.

  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Well, the problem with the first may have been that you used = rather than Like, which you would need with the wildcards:

    If Me.[Card VIN] Like "*CARD*" Then

    Does the field have a space or an underscore? You've got it both ways.
    Last edited by pbaldy; 01-14-11 at 14:36. Reason: fix spelling
    Paul

  3. #3
    Join Date
    Dec 2009
    Posts
    39
    Has anyone told you how awesome you are!?! I am not sure why that showed with an underscore, but the "Like" worked. I don't know why I didn't think of that!

    Thanks again!

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    LOL! No, my friends all tell me what a dummy I am.

    Glad it worked for you.
    Paul

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by SRR View Post
    ...I am not sure why that showed with an underscore...
    When you give a control a name that has a space in it, like Card VIN, then go into the code module and reference it, by typing Me. the dropdown that appears listing available properties and controls will list it as Card_VIN with the underscore.

    Access will do the same thing if you click on the ellipsis of a control's property in order to go to the corresponding event in the code module.

    Linq ;0)>
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •