Runtime error 2185

G

Guest

I have an odd occurrence of this error ("You can't reference a property or
method for a control unless the control has the focus").

I have a continuous form that has text boxes in the header. These are used
as filters for the form. One is for the client and two are for a date range.
I apply the filter by a reference to the control in the Where clause in the
form's record source and simply do a Me.Requery after the update of any of
the filtering controls.

WHERE ((([Forms]![TimeLog]![FilterClientID]) Is Null)) OR
((([Forms]![TimeLog]![FilterClientID]) Is Not Null) AND
((TimeLog.ClientID)=[Forms]![TimeLog]![FilterClientID]));

This simply stipulates that if the ClientID filter is null, show records for
all clients; otherwise show the records pertaining to the selected ClientID.
The date filter Where clauses are like this (one for <=DateFrom, the other
for >+DateTo):

WHERE ((([Forms]![TimeLog]![FilterDateFrom]) Is Null)) OR
((([Forms]![TimeLog]![FilterDateFrom]) Is Not Null) AND
((TimeLog.DateFrom)>=[Forms]![TimeLog]![FilterDateFrom]));

This simply specifies that if the date filter is null, show all dates from
the beginning of time; otherwise show dates from the filter date forward.

Here is the problem: when (and only when) the client filter is populated and
I click on either of the two date filter fields, I get the 2185 error. Here
is the Click event code (it just selects the entire field so I can easily
edit after clicking):

Private Sub FilterDateFrom_Click()
With Me.FilterDateFrom
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub

The error does not occur when FilterClientID is null or when I remove the
ClientID filter from the Where clause.

Ideas?
 
G

Guest

Still not sure why the error happened, but I just switched from my lazy
method of filtering based on queries that reference the form controls &
switched to the proper (or at least superior) method of building the Where
clause in VBA and using Me.Filter = MyWhereClause.

Problem gone; still don't know why the error is even related to the
references to the control in the queries.
 

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

Top