Searching a name in a subform table via vba using combo box

时间:2016-06-18 20:22:47

标签: vba ms-access

I am trying to make a search filter for names on a subform from a parent form using a combo box, I already managed to do it searching dates, Im trying to do it depending on a client name now... I have, but it doesnt work...

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

I manage to do the search by dates instruction like this....

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

1 个答案:

答案 0 :(得分: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