开发者

Fire update event on keyup

开发者 https://www.devze.com 2023-02-04 22:18 出处:网络
I have textbox (\"D_find\" in its id) on my form witch i use to filter form\'s data using LIKE query.

I have textbox ("D_find" in its id) on my form witch i use to filter form's data using LIKE query.

I have following code:

Private Sub D_find_AfterUpdate()  

    Dim fil  

    fil = Me.D_find  

    If fil = Null Then  
        fil = ""  
    End If  

    Me.Filter = "DeloN Like '" + fil + "*'"  

End Sub

It's working correctly if i press tab or focus some other control on form, but i need to apply filter immediatly after keyup event of the textbox, but i cant to it, because if i use this code in D_find_keyup i always have D_find is NULL, but in current scenario it's always is not null except if it's empty.

The second trouble present in current scenario: after AfterUpdate fired and filter is applied, text color in D_find textbox is going to be white and it rollbacks to black after i type somethin in this textbox (D_find) or cut some text.开发者_开发知识库

--

I'm sorry for my bad English.


If the textbox still has focus, you can use:

NameOfControl.Text

This will contain the text just entered. However, why must you apply the filter immediately, it would be safer in Afterupdate, because you would be sure that all data was entered, and you can set focus back to the search control.

EDIT re Comments

Using a textbox, txtSearch, and a listbox, lstCompanies the following code illustrates the above:

Private Sub txtSearch_Change()
s = "SELECT Key, Company " _
  & "FROM tblCompanies " _
  & "WHERE Company LIKE '*" _
  & Replace(Me.txtSearch.Text, "'", "''") & "*'"

Me.lstCompanies.RowSource = s
End Sub

The listbox returns a gradually diminishing list as letters are added to txtSearch.

0

精彩评论

暂无评论...
验证码 换一张
取 消