Applyfilter on a form - more then one

  • Thread starter Thread starter יריב החביב
  • Start date Start date
×

יריב החביב

Hello,

When Open Form, I want to use two filters on that form.
But dont want to filter the form in the form data but in the code that open
it.
the code is here but it is not work. i triyed "and" statement, but no.
How to write the code ?

DoCmd.OpenForm "FRechivim_for_drisha", acNormal
DoCmd.ApplyFilter , "drisha_code = forms!Fcontract!text59"
DoCmd.ApplyFilter , "PositionTypeCode = forms!Fcontract!fdrishot!PositionCode"

thank you
 
Build the WhereCondition to use with OpenForm:

Dim strWhere As String
With Forms!Fcontract
If Not IsNull(!text59) Then
strWhere = "(drisha_code = " & !text59 & ")"
End If
If Not IsNull(!fdrishot.Form!PositionCode Then
If strWhere <> vbnullstring then
strwhere = strwhere & " AND "
End if
strwhere = strwhere & "(PositionTypeCode = " &
!fdrishot.Form!PositionCode & ")"
End If
End With
DoCmd.OpenForm "FRechivim_for_drisha", WhereCondition:=strWhere

Note that you need extra quotes if these are Text fields, not Number fields,
e.g.:
strWhere = "(drisha_code = """ & !text59 & """)"
For an explanation, see:
Quotation marks within quotes
at:
http://allenbrowne.com/casu-17.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top