Control Source IIF function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doma23
    New Member
    • May 2010
    • 107

    Control Source IIF function

    Hi,
    I have 4 controls, 3 text and 1 combo:
    txtNumber1, txtNumber2, cboCalcOption, txtSum.
    cboCaclOption has two possible value: "calculated " and "stated".

    txtSum in the control source has the following formula:
    Code:
    IIF(cboCalcOption="calculated"; txtNumber1+txtNumber2; null)
    If the cboCalcOption is "stated" I need to allow user to input some number in txtSum control, else it would be calculated.
    The problem is that with this function (or with control source properties) user is not allowed to enter anything in the text control.
    So, instead of null in the function I should somehow put the "user input".

    Thank you!
  • doma23
    New Member
    • May 2010
    • 107

    #2
    Until waiting for reply to see if it's possible to do this directly by using Control Properties, I solved it by using VBA. Although, I'm still waiting to see if somebody knows if it can be done by using Control Properties. However, I have another question (I'm quite curious guy :-) It's about good coding practice.

    On txtNumber1, txtNumber2, cboCalcOption I have put AfterUpdate event which calls CalculatedField s sub.

    In CalculatedField s sub are calculations for all 15 cases same like this, that I have on form.
    So if I put something in txtNumber1 it will also check cboCalcOption2 and txtNumber3 and txtNumber4, and also other fields 10-15 times like that.

    I was wondering is it better to make multiple subs seperating each calculation.
    So, for the first occurrence I would call CalculateField1 with only one formula, for the second I would call CalculateField2 with other formula and controls just regarding that field, and so on...

    Does it make any difference or maybe with computer speed we have today and this type of small programs it's unnoticeable?

    Tnx!

    Comment

    • colintis
      Contributor
      • Mar 2010
      • 255

      #3
      I'll just reply to the question you are curious of.

      If you want to prevent checking something that needs to repeat the same things for 15 times, just because it has different field name. You can consider putting parameters in the sub. Such as this one placed in the module.
      Code:
      Public Sub FormatTextbox(ByRef pMyTextBox as Control)
          With pMyTextBox
              .BackColor = 0
          End With
      End Sub
      Last edited by colintis; Sep 14 '10, 01:51 AM.

      Comment

      • doma23
        New Member
        • May 2010
        • 107

        #4
        Ah, great!
        So, for example, I would call sub like this after update of txtNumber1 --> Call SubName (txtSum1), and after update of txtNumber5 (second formula) --> Call SubName (txtSum2) ?

        Comment

        • colintis
          Contributor
          • Mar 2010
          • 255

          #5
          Yes, as long as you are putting the things you need to the right variables that calculate the sum. Give a try and post the code if you have trouble.

          Comment

          Working...