2017-02-04 50 views
0

我想根據我的組合框過濾器篩選我的子表單。我收到代碼錯誤。我需要幫助。訪問子表單的選擇取決於組合框

更新後,我寫了一個事件:

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

回答

0

字符串值使用引號 - 和重新查詢我只需要你沒有改變記錄來源:

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

相關問題