我尝试根据另一个组合框的选择动态设置一个组合框的值。每次运行时都会说对象变量或者没有设置块变量
Option Compare Database
Private Sub cmbReport_AfterUpdate()
'Gets the Report
If cmbReport = "Audit type" Then
Set Data = CurrentDb.CreateQueryDef("", "SELECT AuditTypeName FROM tblAuditType")
End If
Set rs = Data.OpenRecordset
'Sets the data
With Me.cmbData
.Recordset = rs
End With
End Sub
答案 0 :(得分:3)
如果cmdData是一个组合框,它应该是.Rowsource
而不是.Recordset
Private Sub cmbReport_AfterUpdate()
If cmbReport = "Audit type" Then
cmbData.Rowsource = "SELECT AuditTypeName FROM tblAuditType"
End If
End Sub