Fred Boer said:
Hi Dirk:
I spoke a bit too soon... I am still having problems, and I think I
might have a clue why I couldn't make it work earlier; I was using a
combobox for my filter field instead of a text box. If I use the
shortcut "Filter For:" on a *Text* field it works perfectly. However,
if I attempt to do a filter on a combobox control, I get error(s)...
The only visible error message is 2001 "Cancelled previous". However,
I set some break points and I have uncovered the following error
message:
The expression you entered as a query parameter produced this error:
'The object doesn't contain the Automation object
'Lookup_cboPubPlace.PubPlace."
Anyway.. I'm starting to work on this to see if I can figure this one
out.. if I can't I might post back. If you don't mind could you
please check back here over the next day or so?
Sure, but I can tell you a little bit about your problem now. This is
the situation as I understand it. The value your combo box is
displaying comes from some column other than the bound column. When you
ask Access to filter on this value, it is "aware" of this and uses a
hidden query, "Lookup_cboPubPlace", to lookup the bound-column value
that has to be filtered on.
Consider this example: suppose your combo box's rowsource provides
these two columns of data:
1, "Fred"
2, "Dirk"
3, "Jeff"
Suppose also that the bound column is column 1, the number, but you're
displaying column 2, the name. Now you go to filter your form for all
records with the value "Fred" in the combo box. But "Fred" isn't
actually stored in the data, because this isn't the bound column.
Therefore, what I think Access does is build a query to look up the
bound-column value that corresponds to the displayed value (or it may
already have created the query to use with the combo box, I'm not sure),
join the form's recordsource to that query, and make a filter that
applies your criterion to the looked-up field from that query. I should
say that this is just my conclusions based on some fooling around I did
with this a long time ago; it shouldn't be taken as gospel.
In the case of your form, code, and error message, "Lookup_cboPubPlace"
is the name of the hidden query Access is using to filter the form. The
problem is that, when you go to use that filter yourself, as in your
DLookup, you don't have access to that hidden query.
As I said, I fooled around with this for a while a couple of years ago.
I was thinking about developing a general-purpose mechanism for
transforming such lookup references in filters into criteria that could
be applied directly recordsources, outside of built-in filtering
process. I was still struggling with it when other matters intervened,
and I put it aside, and haven't picked it up since.
I'm going to think about it a bit more now. In your case, if you don't
need a general solution, you can probably take the filter, parse out all
the criteria that refer to combo or listbox lookups, and transform them
yourself into corresponding criteria that refer only to the data
actually present in the recordsource. That would be a bit of work and
coding, but not really all that complicated if you know the names of the
combos in question.
Alternative to that would be finding a different way to accomplish your
greater goal, which as I understand it is just displaying a message if
the user tries to apply a filter that returns no records.
I'll get back to you.