我有一個訪問數據庫,這與我提到的上一個問題類似,有一個下拉和一個子窗體。我希望能夠從下拉列表中選擇一個選項,並在下面的子表格中打開相應的子窗體。這裏是我的代碼...訪問編譯錯誤:參數不可選
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新手
錯誤發生在哪裏? – SeanC
at cmbSelectFrms_AfterUpdate事件 – designspeaks
您是手動寫出'cmbSelectFrms_AfterUpdate'還是隻是使用下拉列表(或表單屬性)來創建事件觸發器?有時候事件觸發器的參數是'(這不是可選的......因此是你的錯誤信息!)'如果你沒有從VBE的下拉菜單或屬性框中的事件處理程序構建它們,你就不會意識到這個問題 –