我有一个访问表单,其中包含从表中填充的表单名称的下拉列表。当有人从下拉列表中选择特定项目时,我希望能够显示相应的子表单中的 1 个。例如,我在下拉列表中有表格 1、表格 2、表格 3。我选择表格 2,然后出现子表格 2。我尝试访问 VBA 中的子窗体可见属性,但遇到了多个错误,它从来没有完全奏效。任何人都可以帮忙吗?
这是填充下拉列表的代码:
Private Sub Form_Load()
Dim dba As Database
Dim rst As Recordset
Dim SQL As String
Set dba = CurrentDb
Set rst = dba.OpenRecordset("tbl_Forms", dbOpenDynaset, dbSeeChanges)
SQL = "SELECT ListName FROM tbl_Forms"
Set rst = dba.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
Set rst = Nothing
Set dba = Nothing
End Sub
对于我尝试的子表单可见性:
forms!mainform.Form1.visbile = false
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = false
Select case dropdown
case 1
forms!mainform.Form1.visbile = true
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = false
case 2
forms!mainform.Form1.visbile = false
forms!mainform.Form2.visbile = true
forms!mainform.Form3.visbile = false
case 3
forms!mainform.Form1.visbile = false
forms!mainform.Form2.visbile = false
forms!mainform.Form3.visbile = true
end select