我有一个访问数据库,这与我之前提出的问题类似,带有一个下拉列表和一个子表单。我希望能够从下拉列表中选择一个选项,并让它在下面的子表单中打开相应的子表单。这是我的代码...
Option Compare Database
Option Explicit
Private Sub btnCloseHRForms_Click()
DoCmd.Close
End Sub
Private Sub cmbSelectFrms_AfterUpdate()
Select Case selectSubform
Case 1
Forms!frm_HRForms!subformHRForms.Form!subform1.Visible = True
Case 2
Forms!frm_HRForms!subformHRForms.Form!subform2.Visible = True
Case 3
Forms!frm_HRForms!subformHRForms.Form!subform3.Visible = True
End Select
End Sub
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
Function selectSubform(ID)
Dim dbacurrent As Database
Dim rstcurrent As Recordset
Dim SQL As String
Set dbacurrent = CurrentDb
SQL = "SELECT * FROM tbl_Forms WHERE ID = " & ID
Set rstcurrent = dbacurrent.OpenRecordset(SQL, dbOpenDynaset, dbSeeChanges)
selectSubform = rstcurrent.Fields("ID")
Set dbacurrent = Nothing
Set rstcurrent = Nothing
End Function
有什么建议么?访问 VBA 的新手