Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2009
    Posts
    17

    Unanswered: Forms - "If X then Y" Question

    Hello,

    Problem: In a form, I would like to create a label that displays only when certain values are entered into another field. For example, "If Cell A = 1, then Label 1 will be displayed." "If Cell A = 2, then Label 2 will be displayed."

    If this function is possible, I would also like to be able to take it one step further and tie two fields into one label. Thereby, "If Cell A = 1 and Cell B = US, then Label 1 will be displayed."

    Thank you for your timely response.

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    Welcome to the forums!

    Not sure how refined your VB skills are, but it sounds like you're going to have to do some coding. I would write something like the following in the KeyUp event of your textbox:
    Code:
    If (me.Textbox1NameHere = 1) AND (me.Textbox2NameHere = US) Then
        me.LabelNameHere.visible = true
    Else
        me.LabelNameHere.visible = False
    End If
    Give that a try and let us know if you need more than that.
    Me.Geek = True

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    ...and put the code in the forms on current event and I'd also suggest the contols on change event
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I'd use the control's AfterUpdate event rather than the OnChange, simply because the OnChange fires with every character entered, while AFterUpdate only fires after all data has been entered. But OnChange is certainly preferable to KeyUp event.

    Also, the bit of code

    me.Textbox2NameHere = US

    would have to be

    me.Textbox2NameHere = "US"
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    after update will change the label after the update evetn has fired

    On change or on lost focus would in my books be a better bet for this op in my books. but as ever its semantics its down to personal preference

    in any event the code (or call to the function) should be placed in the on current event so that as the user scrolls through the records the label is set correctly for existing records
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by healdem
    in any event the code (or call to the function) should be placed in the on current event so that as the user scrolls through the records the label is set correctly for existing records
    Absolutely!
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    May 2005
    Posts
    1,191
    Good call fellas. I just came up with that code off the top of my head, I didn't really test it all, thanks for the follow ups!
    Me.Geek = True

Posting Permissions

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