访问子表单的选择取决于组合框

访问子表单的选择取决于组合框

问题描述:

我想根据我的组合框过滤器筛选我的子表单。我收到代码错误。我需要帮助。访问子表单的选择取决于组合框

更新后,我写了一个事件:

Private Sub cboSelected_AfterUpdate() 
Dim MyName As String 
MyName = " select * from [ITP_Checklist Log] where ([ITP_Checklist Log].[Name] = " & Me.cboSelected & ")" 

Me.ITP_Checklist_Log_subform.Form.RecordSource = MyName 

Me.ITP_Checklist_Log_subform.Form.Requery 

End Sub 

错误:

Run-time error '3464' 
Data Type Mismatch in Criteria expression. 

enter image description here

enter image description here

字符串值使用引号 - 和重新查询我只需要你没有改变记录来源:

Private Sub cboSelected_AfterUpdate() 

    Dim MyName As String 

    MyName = "select * from [ITP_Checklist Log] where ([ITP_Checklist Log].[Name] = '" & Me!cboSelected.Value & "')" 

    Debug.Print MyName 

    If Me!ITP_Checklist_Log_subform.Form.RecordSource = MyName Then 
     Me!ITP_Checklist_Log_subform.Form.Requery 
    Else 
     Me!ITP_Checklist_Log_subform.Form.RecordSource = MyName 
    End If 

End Sub 
+0

感谢您的回答@Gustav。但是这次得到了编译错误:语法错误 – srinivas

+0

用'Debug.Print'插入这行并告诉我们你看到了什么。 – Gustav

+0

它突出显示与红色.. ..如果我!ITP_Checklist_Log_subform.Form.RecordSource =我的姓名 – srinivas