How to save calculated values in MS Access

前端 未结 3 1118
花落未央
花落未央 2021-01-26 22:27

I have a textbox in a form that I created.

I want to add an expression in the textbox\'s Control Source property. I also want to bind the textbox to a field in the tabl

相关标签:
3条回答
  • 2021-01-26 23:05

    If you have a text box named txtMy_field which is bound to a field named My_field in your form's record source, you could use the form's on current event to load the sum of those other two numbers into txtMy_field.

    If you don't want to over-ride existing values stored in My_field ...

    If IsNull(Me.txtMy_field) = True Then
        Me.txtMy_field = Number1 + Number2
    End If
    

    If you do want to over-ride existing values stored in My_field, eliminate the IsNull() condition.

    Me.txtMy_field = Number1 + Number2
    

    If Number1 and Number2 are from other controls on your form, you could also use their after update events to update txtMy_field value on demand.

    However, I'm unsure how well I understand your question. These are only general suggestions and I hope they point you to something useful. Incidentally, if those two numbers come from two different forms (as in one of your previous questions) and you intend to display and store their sum via a third form, this could be more challenging than it appears from this question.

    0 讨论(0)
  • 2021-01-26 23:06

    You could link the text box to the table control source and then set the value of the text box to the result of the expression in the AfterUpdate property on the two objects the contain the values you want to add.

    For example

    me.textbox.value= int1 + int2
    

    This value should then be written to the table.

    0 讨论(0)
  • 2021-01-26 23:15

    If you have textboxes with names text1 and text2 and you will save your answer in text3 you should give this code in text3 properties Control Source:

    =Val([text1])+Val([text2])
    
    0 讨论(0)
提交回复
热议问题