Filtering Problem!

  • Thread starter Thread starter Sam Hung
  • Start date Start date
S

Sam Hung

Hi All,

Can I filter the data from the database and show it in
the form as two filter items are selected?

My Source Code is as follows:
Private Sub text1_KeyDown(KeyCode As Integer, Shift As
Integer)
If KeyCode = 13 Then
Me.Filter = "table1.text1='" & Trim(text1.Text) & "'
and cust_fg_mat_bill.text2='" & Trim(text2.Text) & "'"
Me.FilterOn = True
End If
End Sub

'the above filter command doesn't work, it shows "Run-
Error '2185'"
"You can't reference a property or method for a control
unless the control has the focus."

Sam.
 
Hi Sam,

You don't need to use the text property to get the value of a control. The
'text' property on an Access control is not the same as on a VB control. The
'Value' property more closely matches the VB 'text' property. Since the
Value property is the default property of a control you don't have to
specify it at all so the following are the same:

me.text1=null
me.text1.Value=null

In Access, the 'text' property is only valid when the control has the focus
and it is used to differientiate what the user has typed from what is saved
in the control. When the control looses focus, the 'text' property is no
longer relevant since a value is already saved in the control.

Private Sub text1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then
Me.Filter = "table1.text1='" & Trim(me.text1) & "' and
cust_fg_mat_bill.text2='" & Trim(me.text2) & "'"
Me.FilterOn = True
End If
End Sub

Also, I'm not sure you would really want to use the KeyDown event of control
for this - I'd recommend going with the AfterUpdate event of the control to
reduce the overhead of the filtering.
 
Back
Top