Override form recordsource with filter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gerry Goldberg
    New Member
    • Jul 2010
    • 11

    Override form recordsource with filter

    How does a form's FILTER criteria work? If I specify a query in the form's recordsource, and then in VBA specify a form filter criteria, does the filter criteria override what was originally specified in the recordsource query?

    For example, in the form's recordsource, I have specified: SELECT * FROM tblA WHERE Account='12345' . Later in VBA code, I specify filter = "Account='98765 ' filteron=true. Should the vba override the recordsource?

    What if I specify a criteria for the filter that's not in the recordsource? Does it get appended to the recordsource, or replace the WHERE clause in the recordsource.

    I can't seem to prove anything one way or another, but I know that my recordsource isn't working right when I add the filter specification.

    Thanks,

    Gerry Goldberg
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    #2
    VBA doesn't override anything. VBA allows you to set properties of objects, as well as manipulating objects.
    Your object here is a form. The property RecordSource you are setting to "SELECT * FROM tblA WHERE Account='12345' ". I would assume that this means that you have a RecordSource consisting of one record.
    The Filter property of a form applies that filter to the form's RecordSource property. In this case, the result will be an empty recordset. I would expect errors such as 'No current record'.
    If you are always going to 'know' the Account, then RecordSource = tblA would work, and the record shown would be the one specified with Filter = '12345' or Filter = '98765'.

    Comment

    Working...