我正在研究访问 2010 数据库。我对此很陌生,对VBA知之甚少。
我有一个表单(基于查询),在文本框中显示某些项目的测试频率。它被命名为“TestFrequency”
然后我有 3 个组合框(分别命名为: Year1 、 Year2 和 Year3 )。
我添加了一个按钮并在“Onclick”中创建了一个事件,我试图做的是根据测试频率值设置组合框的值。我还添加了一些消息框以在事件完成时弹出。
我尝试使用以下代码但无法正常工作:
Private Sub Reset_Click()
Dim Response As VbMsgBoxResult
Response = MsgBox("Do you want to reset planning to default test frequency?", vbQuestion + vbYesNo, "Planning Settings")
If Response = vbNo Then Exit Sub Else
Dim ctrl AS Controls
For Each ctrl From Me.Controls
If TestFrequency.Value = "Test Annually" Then
Me.Year1.Value = "Yes"
Me.Year2.Value = "Yes"
Me.Year3.Value = "Yes"
ElseIf TestFrequency.Value = "Test Every 2 years" Then
Me.Year1.Value = "No"
Me.Year2.Value = "Yes"
Me.Year3.Value = "No"
ElseIf TestFrequency.Value = "Test every 3 years" Then
Me.Year1.Value = "No"
Me.Year2.Value = "No"
Me.Year3.Value = "Yes"
ElseIf TestFrequency.Value = "Ad-hoc" Then
Me.Year1.Value = "No"
Me.Year2.Value = "No"
Me.Year3.Value = "No"
End If
Next ctrl
MsgBox "Settings were changed.", vbInformation
End If
End Sub
有人能帮帮我吗?谢谢!