2016-06-18 23 views
0

我正在嘗試使用組合框爲父窗體上的窗體上的名稱創建搜索過濾器,我已經設法執行搜索日期,我正在嘗試執行這取決於客戶的名字,現在......我有,但它不工作...使用組合框通過vba在子窗體表中搜索名稱

Me.subform.Form.Filter = "[Client]=& me.cboClientName&" 

我能做到通過這樣的日期指示搜索....

Me.subform.Form.Filter = "[AppointDate]=#" & Format(Me.cbSelectDate, "yyyy-mm-dd") & "#" 

回答

1

你必須將字符串連接到搜索列和組合框的值,並且必須應用過濾器。

Dim strFilter as string 

'first print what you did 
strFilter = "[Client]=& me.cboClientName&" 
Debug.Print "Your faulty filter: " & strFilter ' shown in immediate window 

'now with concat 
strFilter = "[Client]= '" & Me.cboClientName & "'" ' suround by quotes because I assume it's a string 
Debug.Print "filter: " & strFilter 

Me.subform.Form.Filter = strFilter 
Me.subform.Form.FilterOn = true ' activate the Filter 
+0

謝謝它像一個魅力工作! –