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.
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.