Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Posts
    5

    Unanswered: Have a form input field appear or disappear based on Item Selceted

    Hello All,

    I am venturing into my first complex Access development project and could use some pointers in the right direction. If you look at the screenshot I have attached, you will get a better idea of what I am talking about in this post.

    I created an input form that contains a combo box named incident status. If "litigation" is selected in the incident status combo box, an input fields for "litigation attorney" and "litigation venue" should appear on the input form. If the status is anything but "litigation" they are not relevant and therefore should not be visible.

    I am thinking that the solution will be to go ahead and draw inputs for "litigation attorney" and "litigation venue" and set the visible property to no.

    I am assuming that some basic VB code attached to the LitigationStatus combo box will be used to accomplish this. However, I am a little unclear on how to implement this. The general idea will be to somehow say "if IncidentStatus.ItemSelected=Litigation then LitigationVenue.Visible=Yes"
    Attached Thumbnails Attached Thumbnails Database_Screen.jpg  

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Have you tried it? You have the idea right, using an If statement in conjunction with the Visible property. All you need to do is do it!

    Put the code in the AfterUpdate for the combo box and also call it from Form_Current. Should be good to go
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    As StarTrekker has said, you're on the right track! You start off with the LitigationAttorney and LitigationVenue textboxes on the form, but initially with their Visible Properties set to No.

    If "Litigation" is chosen from the IncidentStatus combobox, as you have guessed, you need to set their Visible Property to Yes.

    But here, as in most of software development, you also have to think about what happens if your user messes up! What if he/she selects "Litigation," enters an attorney and venue name, and then realizes that he/she has made a mistake! You now would need to undo everything that has been done based on the assumption that Litigation is involved. Besides making the two textboxes invisible, you also need to remove the attorney name and venue that had been entered. So in the AfterUpdate event of the combobox, use code like this:

    Code:
    Private Sub IncidentStatus_AfterUpdate()
     If IncidentStatus = "litigation" Then
       LitigationAttorney.Visible = True
       LitigationVenue.Visible = True
     Else 
       LitigationAttorney.Visible = False
       Me.LitigationAttorney.Value = Null
       LitigationVenue.Visible = False
       Me.LitigationVenue.Value = Null
     End If
    End Sub
    Now, in order that the two textboxes appear or don't appear, depending on what was chosen from from the combobox, you need to repeat most of them sae code in the Form_Current event:

    Code:
    Private Sub Form_Current()
     If IncidentStatus = "litigation" Then
       LitigationAttorney.Visible = True
       LitigationVenue.Visible = True
     Else
       LitigationAttorney.Visible = False
       LitigationVenue.Visible = False
     End If
    End Sub
    Two last notes:

    All of this is based on the IncidentStatus combobox being bound to a field in the underlying table.

    This kind of thing can only be done in a Single View Form. Doing this kind of formatting in a Datasheet View or Continuous View Form is really not feasible.
    Last edited by Missinglinq; 01-28-09 at 22:20.
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Jan 2009
    Posts
    5
    Wow! Thanks for the incredible bit of help.

    I guess the only thing I am really having trouble with is making this happen in real time. The form opens and the user begins to fill it out. The second litigation is selected, the attorney and venue inputs appear.

    Is this possible?

  5. #5
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Yes. Have you tried it?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Quote Originally Posted by gulfwebdev
    I guess the only thing I am really having trouble with is making this happen in real time. The form opens and the user begins to fill it out. The second litigation is selected, the attorney and venue inputs appear.
    What do you mean by "real time?" Waht do you mean by "second litigation?" Have you tried the code supplied?
    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
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Real time = real time, not turn based ^^

    Second Litigation is one of his selections for his combo box.

    The only real question is "have you tried it"?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Jan 2009
    Posts
    5
    Sorry for the delay on getting back with results.

    My problem is that I have the right idea in my head as what needs to be done. Now I even have the code. My problem is that I do not know exactly how to implement it. I have no experience adding VBA to accesss forms.

    I found the "View Code" icon and started adding the suggested code. Didn't work! Thankfully I have experience with troubleshooting basic code and started eyeballing the usual suspects. Found a name that needed to be changed, etc.

    Second try.... WORKED PERFECTLY!!!

Posting Permissions

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