Filtering Problem!

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

Sandra Daigle

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.
 

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