首页 > 解决方案 > 如何使用 VBA 将文本框中输入的值分配给另一个表单 MS Access 上的组合框选择

问题描述

我有一个包含 6 个文本框的表格,其中 3 个保存月度、季度和年度会员类型的更新货币价值。In another form I have a combobox with the 3 types of membership, when a membership type is selected I want to output the updated monetary value of the selection to a textbox. 如果有人可以帮助/推荐任何足智多谋的链接,将不胜感激。我对 vba 的理解还不错,但是在编写正确运行的代码时遇到了困难。


Private Sub cbMmemberType_change()

 If cbMemberType.Text = "Monthly" Then
        frmSubscriptionDetails.txtSubCost.Text = frmUpdatedCosts.txtUpdatedMonth.Text
    ElseIf cbMemberType.Text = "3 Months" Then
         frmSubscriptionDetails.txtSubCost.Text = frmUpdatedCosts.txtUpdated3Months.Text
    ElseIf cbMemberType.Text = "Annual" Then
         frmSubscriptionDetails.txtSubCost.Text = frmUpdatedCosts.txtUpdatedAnnual.Text

    End If

End Sub

标签: vbams-access

解决方案


Text属性仅在控件具有焦点时有效,并使用AfterUpdate事件,因此请尝试:

Private Sub cbMmemberType_AfterUpdate()

    Select Case Me!cbMemberType.Value
        Case "Monthly" 
            frmSubscriptionDetails!txtSubCost.Value = frmUpdatedCosts!txtUpdatedMonth.Value
        Case "3 Months" 
            frmSubscriptionDetails!txtSubCost.Value = frmUpdatedCosts!txtUpdated3Months.Value
        Case "Annual" Then
            frmSubscriptionDetails!txtSubCost.Value = frmUpdatedCosts!txtUpdatedAnnual.Value
    End Select

End Sub

推荐阅读