在Access窗体上动态设置组合框的值

时间:2014-08-15 14:12:42

标签: vba ms-access

我尝试根据另一个组合框的选择动态设置一个组合框的值。每次运行时都会说对象变量或者没有设置块变量

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

1 个答案:

答案 0 :(得分:3)

如果cmdData是一个组合框,它应该是.Rowsource而不是.Recordset

Private Sub cmbReport_AfterUpdate()
    If cmbReport = "Audit type" Then
        cmbData.Rowsource = "SELECT AuditTypeName FROM tblAuditType"
    End If
End Sub