我希望在"主要信息"表单中编程一个单击事件,该表单将根据在多答案查找字段组合控件(对应于通过独立的单独表相关的数字ID字段/文本字符串类别)中选择的值打开多达17个其他表单。
我学过了这是通用代码:
Private Sub DiagCat_AfterUpdate()
Select Case DiagCat
Case "Cancer [140-208]"
DoCmd.OpenForm (Cancer_Form)
Case "Heart Disease [393-398, 402, 410-429]"
DoCmd.OpenForm (Heart_Disease_Form)
Case "Stroke [430-438]"
DoCmd.OpenForm (Stroke_Form)
Case "Diabetes [250]"
DoCmd.OpenForm (Diabetes_Form)
Case "Hypertension [401]"
DoCmd.OpenForm (Hypertension_Form)
Case "Liver Disease [070, 571-573]"
DoCmd.OpenForm (Elevated_Cholesterol_Form)
End Select
End Sub
VBA现在发出"Type Mismatch"错误13;在Case "Cancer[140-208]"'行执行错误。
谢谢。
Select Case
关键字是根据一个字段的多个值选择操作所需的关键字。
Private Sub cmdOpen_Click() 'where cmdOpen is the button control clicked to open the forms
Select Case cmbDxCatsID 'assuming cmbDxCatsID is the name of the combobox control on the form
Case 1
DoCmd.OpenForm(Form1)
Case 2
DoCmd.OpenForm(Form2)
'etc.........
End Select
End Sub