有一个访问数据库,其表单具有用于生产数据的多个文本框。我需要做的几个箱子的计算,他们被设置为在VBA中的计算
txtA * txtB * txtC = txtD
我需要从每个盒子的取值和履行本幕后计算。所以我需要txtA * txtB * txtC的值,并在txtD中显示该计算的答案。我一直在遇到问题,因为我的窗体上的文本框的数量总是会选择错误的数据?帮帮我!
Private Sub btnCalculate_Click()
Dim ctrl As Control
Dim txt As TextBox
For Each ctrl In Form.Controls
If TypeOf ctrl Is TextBox Then
Set txt = ctrl
If txt.Name = "txtD" Then
Set txt = ctrl
ctrl.SetFocus
ctrl.Text = calculate
End If
End If
Next ctrl
End Sub
Public Function calculate()
Dim calc1 As Double
calc1 = txtA.Value * txtB.Value * txtC.Value/144
End Function
我不断收到此错误:
Run-time error '2185': You can't reference a property or mathod for a control unless the control has the focus.
这是关于txtA,txtB,txtC。
你应该显示你现有的代码:很难知道你去哪里错了,否则... –