none
Suggestions For Displaying Form Controls Conditionally RRS feed

  • Question

  • Pardon my newbieness. 

    I have a combobox in a boundless form. The values in the list are types of fees. For each type of fee there are certain fields that need to be complted. For example, a Flat Fee is just that. One payment. So I only need a text box for entering that amount. If the fee type is Monthly I need several fields completed such as down payment, interested, number of months, etc. 

    Currently I have a text box for EVERY possible value that I might need, and I just enable them or disable them in code based on the fee types afterupdate event. BUT..obviously that's a lot of wasted real estate. I thought about leveraging the Visible property instead, but the fields still need a place to be even if they are not visible. 

    Okay...so, what is a good recommendation for doing this? Should I have an array of controls that are created and destroyed based on the fee type. Example, create this array of five text boxes and their labels OR this other array of three text boxes labels. If so just some general guidance would be great. 

    Any other ideas.

    Thanx,

    tod

    Wednesday, September 14, 2016 7:57 PM

Answers

  • I would create all the controls you need in Design View, and set their Visible property to No.

    During runtime, make controls visible based on the value of the fee type combo box.

    To avoid wasting space, controls that will never be displayed simultaneously can be placed on top of each other.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by todtown Wednesday, September 14, 2016 9:44 PM
    Wednesday, September 14, 2016 8:33 PM
  • Hi tod,

    If you're using a "boundless" form anyway, maybe you could just assign the applicable fields to each control based on fee type. For example, let's say you have an unbound Textbox called "txtFee" and if the fee type is "cash", then you need to store the data to a field called CashFee, and if the fee type is "credit", then you need to store the data into a field called CreditFee. If so, you might be able to use something like this:

    Select Case Me.FeeType
        Case "cash"
            Me.txtFee.ControlSource = "CashFee"
        Case "credit"
            Me.txtFee.ControlSource = "CreditFee"
    End Select

    Just a thought. Hope it helps...

    • Marked as answer by todtown Wednesday, September 14, 2016 9:44 PM
    Wednesday, September 14, 2016 9:08 PM

All replies

  • I would create all the controls you need in Design View, and set their Visible property to No.

    During runtime, make controls visible based on the value of the fee type combo box.

    To avoid wasting space, controls that will never be displayed simultaneously can be placed on top of each other.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by todtown Wednesday, September 14, 2016 9:44 PM
    Wednesday, September 14, 2016 8:33 PM
  • Hi tod,

    If you're using a "boundless" form anyway, maybe you could just assign the applicable fields to each control based on fee type. For example, let's say you have an unbound Textbox called "txtFee" and if the fee type is "cash", then you need to store the data to a field called CashFee, and if the fee type is "credit", then you need to store the data into a field called CreditFee. If so, you might be able to use something like this:

    Select Case Me.FeeType
        Case "cash"
            Me.txtFee.ControlSource = "CashFee"
        Case "credit"
            Me.txtFee.ControlSource = "CreditFee"
    End Select

    Just a thought. Hope it helps...

    • Marked as answer by todtown Wednesday, September 14, 2016 9:44 PM
    Wednesday, September 14, 2016 9:08 PM
  • I thought about putting controls on top of each other and making only one in the stack visible. It seemed awkward to do in design mode, so thought I'd fish for other ideas. I may still consider it. Thanx.
    • Marked as answer by todtown Wednesday, September 14, 2016 9:44 PM
    • Unmarked as answer by todtown Wednesday, September 14, 2016 9:44 PM
    Wednesday, September 14, 2016 9:39 PM
  • I have an idea for a solution that would use basically a combination of what you and Hans have suggested. Determine the most number of text boxes I'll need for any one fee type. Say it's five. Okay. Make room on the form for five text boxes and their associated labels. Set the visible property on all of them to false. Then based on the fee type, have my code specify how many to show, from left to right and set the properties for each. Then when the user clicks Submit have my query designed to leverage the visible text boxes and fee type. 

    Thanx guys.

    tod

    Wednesday, September 14, 2016 9:43 PM
  • I thought about putting controls on top of each other and making only one in the stack visible. It seemed awkward to do in design mode, so thought I'd fish for other ideas. I may still consider it. Thanx.

    Hi todtown,

    No problem to stack all invisible controls. At the moment you need one, you can make it visible, bind it to the wanted field, and place it on the position where you want it.

    Imb.

    Wednesday, September 14, 2016 9:54 PM