Apply filter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    Apply filter

    Hi all,
    A form based on a query (qry_source_tra ilers) contains the field
    [bookref]. In the forms header, I have placed an unbound text box where the
    afterupdate property is set to:
    DoCmd.ApplyFilt er , "bookref = forms!frm_trail ers!txt_find_br ef" This works
    fine but I would like to change the filter property to Like instead of
    equals due to some of the booking references being very long.

    I've tried DoCmd.ApplyFilt er , "bookref like " *
    "&forms!frm_tra ilers!txt_find_ bref&" * "" which throws up a type mis-match.
    Could anyone offer any guidance?

    TIA,

    Mark


  • Allen Browne

    #2
    Re: Apply filter

    Assuming bookref is a Text field (not a Number field), try:
    Dim strWhere As String
    strWhere = "bookref like """*" & forms!frm_trail ers!txt_find_br ef &
    "*"""
    DoCmd.ApplyFilt er , strWhere

    The odd quotes are because you need to end up with a string that looks like
    this:
    bookref Like "*peace*"
    and you have to double-up the quotes when they are embedded. To help get it
    right, you could:
    Debug.Print strWhere
    and then look in the Immediate Window (Ctrl+G) after it runs.

    --
    Allen Browne - Microsoft MVP. Perth, Western Australia.
    Tips for Access users - http://allenbrowne.com/tips.html
    Reply to group, rather than allenbrowne at mvps dot org.

    "Mark" <mark.reed75@nt lworld.com> wrote in message
    news:TlGqd.49$6 93.46@newsfe1-gui.ntli.net...[color=blue]
    >
    > A form based on a query (qry_source_tra ilers) contains the field
    > [bookref]. In the forms header, I have placed an unbound text box where
    > the afterupdate property is set to:
    > DoCmd.ApplyFilt er , "bookref = forms!frm_trail ers!txt_find_br ef" This
    > works fine but I would like to change the filter property to Like instead
    > of equals due to some of the booking references being very long.
    >
    > I've tried DoCmd.ApplyFilt er , "bookref like " *
    > "&forms!frm_tra ilers!txt_find_ bref&" * "" which throws up a type
    > mis-match.
    > Could anyone offer any guidance?[/color]


    Comment

    • Mark

      #3
      Re: Apply filter

      Many thanks for your help and explanation again Allen. Worked a treat.

      Regards,

      Mark

      "Allen Browne" <AllenBrowne@Se eSig.Invalid> wrote in message
      news:41abcca2$0 $25779$5a62ac22 @per-qv1-newsreader-01.iinet.net.au ...[color=blue]
      > Assuming bookref is a Text field (not a Number field), try:
      > Dim strWhere As String
      > strWhere = "bookref like """*" & forms!frm_trail ers!txt_find_br ef &
      > "*"""
      > DoCmd.ApplyFilt er , strWhere
      >
      > The odd quotes are because you need to end up with a string that looks
      > like this:
      > bookref Like "*peace*"
      > and you have to double-up the quotes when they are embedded. To help get
      > it right, you could:
      > Debug.Print strWhere
      > and then look in the Immediate Window (Ctrl+G) after it runs.
      >
      > --
      > Allen Browne - Microsoft MVP. Perth, Western Australia.
      > Tips for Access users - http://allenbrowne.com/tips.html
      > Reply to group, rather than allenbrowne at mvps dot org.
      >
      > "Mark" <mark.reed75@nt lworld.com> wrote in message
      > news:TlGqd.49$6 93.46@newsfe1-gui.ntli.net...[color=green]
      >>
      >> A form based on a query (qry_source_tra ilers) contains the field
      >> [bookref]. In the forms header, I have placed an unbound text box where
      >> the afterupdate property is set to:
      >> DoCmd.ApplyFilt er , "bookref = forms!frm_trail ers!txt_find_br ef" This
      >> works fine but I would like to change the filter property to Like instead
      >> of equals due to some of the booking references being very long.
      >>
      >> I've tried DoCmd.ApplyFilt er , "bookref like " *
      >> "&forms!frm_tra ilers!txt_find_ bref&" * "" which throws up a type
      >> mis-match.
      >> Could anyone offer any guidance?[/color]
      >
      >[/color]


      Comment

      Working...