access table form bug?

M

madhouse

Hi
I wonder if i've found a bug in access?
The odd behaviour happens in access 97 and access 2003.
I have a v small db in 97 format that easily reproduces
the problem. See below.
I have a table form.
Detail section of the form runs the standard show rows
from bound table
The header section of the form has 3 buttons and a data
field. 3 buttons apply filters to the detail section to
show all rows, some rows and no rows. The no rows is
simply a filter that has no matches. The data field has a
keydown event that grabs its text and creates a filter
from the text. The code to do this is:

Private Sub dfTest_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = 13 Then
Me.dfTest.SetFocus
Me.dfTest = dfTest.Text
DoCmd.ApplyFilter , "name = """ & dfTest & """"
KeyCode = 0
End If
End Sub

This works fine if the detail section has some rows
displayed, however when the detail secion has no rows as
a result of the no rows filter button above, an error
occurs:
2182:You can't reference a property or method for a
control unless the control has focus.

You will note that the line preceding the asignment is a
setfocus on the datafield!

You may be wondering why the line me.dftest=dftest.text
exists, this is because the keydown event is fired before
the data-fields edited text has been assigned to the data-
field control, so this lines forces it for use later in
the code.

A zip file containing the demo db may be downloaded at
http://wes21.co.uk/dbbug.zip. Try putting "3" in the test
field and pushing enter, then click filter no rows button
then put "3" in the test field and push enter key and pop
goes the error.

Thanks in advance for anyone who can sort this for me.
 
A

Allen Browne

Access has some very long-standing bugs in this area.

If a form has no record to show, and no new records can be added, then the
detail section goes completely blank. When this happens, the controls in the
Form Header and Form Footer section;
- may not show their data correctly (even though the data is there);
- are likely to get thoroughly confused about what has focus;
- can generate nonsense errors about their Value and Text properties.

AFAIK, there is no solution for the problem, but we have documented the
issues in article:
Incorrect display of data
at:
http://members.iinet.net.au/~allenbrowne/bug-06.html

Sorry: no solution. Hope it helps to know you are not alone.
 
M

madhouse

Thanks Allen
Its good to know that i'm not going mad.
So problem is due to the form not allowing inserts. I set
allow inserts back to Yes and behaviour is now correct,
as you say the detail section now displays (blank) data.
Provided i have locked all the data fields on the detail
section i have my browse window as required.

Is there much work in perth? I'm uk based but seriously
considering emigrating
cheers, madhouse.
 
A

Allen Browne

Great.

Please call if you do make it to Perth. I'm personally busy, but it's a
small market, so can't promise. Perth is really just a large country town
(about 1 million people), so a laid back lifestyle.
 

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