Text Property Bug (demo attached) (1 Viewer)

Galaxiom

Super Moderator
Staff member
Local time
Today, 23:54
Joined
Jan 20, 2009
Messages
12,852
When a filter is applied to a form resulting in no records displaying, the Text property of an unbound control in the header becomes unavailable.

The error is the usual 2185 encountered if the Text property is referred to when the control does not have focus. "You can't reference a property or method of a control unless the control has focus."

However the textbox does have focus. I can see no logical reason for the error except that it is a bug caused by an incorrect assumption that a zero RecordCount on the form automatically means no control can take the focus.

If the AllowAdditions property is True for the form, the New Record prevents the error. For convenience I have included a button to toggle this property in the demo.

A workaround is to put the searched form into a subformcontrol with the search textbox in the main form. However I would be interested in any workarounds that don't require this extra construction.
 

Attachments

  • TextFilterProblem.zip
    16.7 KB · Views: 124

MarkK

bit cruncher
Local time
Today, 06:54
Joined
Mar 17, 2004
Messages
8,183
One handy, though unrelated, tid-bit is that the .Text property never returns null, so you don't have to check for that, but . . .
and I just got error . . .
Code:
2196, Microsoft Office Access can't retrieve the value of this property.
. . . trying to reference the SearchTerm.Text property. Never heard of that error before. More to come. . .
 

MarkK

bit cruncher
Local time
Today, 06:54
Joined
Mar 17, 2004
Messages
8,183
It doesn't even work for an unbound form. I thought I'd try this . . .
Code:
Private Sub SearchTerm_Change()
    Dim where As String
    
    Set Me.Recordset = Nothing
    
    With SearchTerm
        If .Text <> "" Then where = "WHERE Field1 Like """ & .Text & "*"""
    End With
    
    Set Me.Recordset = CurrentDb.OpenRecordset( _
        "SELECT * FROM Table1 " & _
        where)

End Sub
. . . with nothing the recordsource, and it chokes on that too.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 23:54
Joined
Jan 20, 2009
Messages
12,852
Thanks for taking a look Mark.

So basically the Text Property of a control is not available where there is no data on the form.

Definitely a bug in the way the Text property is accessed.
 

ChrisO

Registered User.
Local time
Today, 23:54
Joined
Apr 30, 2003
Messages
3,202
I’m normally very reluctant to call things bugs but I think you have one there.

I don’t think I have seen that before but it is reproducible in Windows XP with Access 2003 (service pack 3 with the hot fix).

Some research indicates that Allen Browne’s ‘Find as you type’ exhibits the same problem:-
http://allenbrowne.com/appfindasutype.html
Open the download and type ‘xx’ and there will be no records. Type a backspace and you can recover to the last filter for ‘x’. Then change the Form’s ‘Allow Additions’ to No and try again. The recovery back to a single ‘x’ does not work because of a masked error in his code under the above condition. In other words, if we remove his error handling we get exactly the same error you got about not being able to get at the Text property.

Therefore it appears to be an old bug, which I haven’t seen before, and I doubt if it will ever get fixed. I can’t think of a better workaround than the one you have suggested.

Chris.
 

Users who are viewing this thread

Top Bottom