Hi, I have a form which shows a list of records. To help the user find the record they want I have a text box txtSiteName which the user types into. On the OnChange event of this there is the following code:
The hidden text box txtSiteNameX is referenced to as the criteria in the underlying query to the list box as follows:
Like "*" & [Forms]![frmFindQuoteRecord]![txtSiteNameX] & "*"
The form and filtering of the records in the list box work fine. However when there are 10+ users logged into the DB it slows down a fair bit meaning there is about a 1 second pause on every character entered, therefore if they need to enter 5/6 characters to filter down enough it can become a bit clunky.
What I was hoping to do was remove the change the requery command the txtSiteName_Change() event and then have it only requery the list box when the user presses 'Enter' having typed the full search string they wanted. I changed the enter key behaviour on the text box to 'New line in field' and added the following code to the the OnKeyPRess event:
Although in principle this works the problem I now have is that by pressing the enter key it does add a new line in what is only a single line text field and therefore the test string the user typed is now out of sight and it looks like the text box is blank. Furthermore if they want to then edit/amend there type string its not easy/obvious as there is nothing showing. I tried to find a way of removing the carriage return from the text box but none of the web solutions seemed to work. I then found by adding the following line of code I could at least remove the second line from the field but it then leaves the typed string highlighted in the field. This isn't ideal as if the user types anything it of course over types the entire string.
So what I need to do is unselect the text in the box and leave the cursor after the last typed character. I have tried all sorts of web suggestions as below but none seem to work, many of which again leave the cursor on a new line in the field which hides the typed text:
Any ideas?
Code:
Private Sub txtSiteName_Change()
Me.txtSiteNameX = Me.txtSiteName.Text
Me.lstJobs.Requery
End Sub
The hidden text box txtSiteNameX is referenced to as the criteria in the underlying query to the list box as follows:
Like "*" & [Forms]![frmFindQuoteRecord]![txtSiteNameX] & "*"
The form and filtering of the records in the list box work fine. However when there are 10+ users logged into the DB it slows down a fair bit meaning there is about a 1 second pause on every character entered, therefore if they need to enter 5/6 characters to filter down enough it can become a bit clunky.
What I was hoping to do was remove the change the requery command the txtSiteName_Change() event and then have it only requery the list box when the user presses 'Enter' having typed the full search string they wanted. I changed the enter key behaviour on the text box to 'New line in field' and added the following code to the the OnKeyPRess event:
Code:
Private Sub txtSiteName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'Enter key
Me.lstJobs.Requery
End If
End Sub
Although in principle this works the problem I now have is that by pressing the enter key it does add a new line in what is only a single line text field and therefore the test string the user typed is now out of sight and it looks like the text box is blank. Furthermore if they want to then edit/amend there type string its not easy/obvious as there is nothing showing. I tried to find a way of removing the carriage return from the text box but none of the web solutions seemed to work. I then found by adding the following line of code I could at least remove the second line from the field but it then leaves the typed string highlighted in the field. This isn't ideal as if the user types anything it of course over types the entire string.
Code:
Private Sub txtSiteName_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then 'Enter key
Me.lstJobs.Requery
Me.txtSiteName = Me.txtSiteNameX
End If
End Sub
So what I need to do is unselect the text in the box and leave the cursor after the last typed character. I have tried all sorts of web suggestions as below but none seem to work, many of which again leave the cursor on a new line in the field which hides the typed text:
Code:
Me.txtSiteName.SelStart = Me.txtSiteName.SelLength
Me.txtSiteName = Left(Me.txtSiteName, Len(Me.txtSiteName) - 1)
Me.txtSiteName = Replace(Nz(Me.txtSiteNameX, ""), Chr(13), "")
Me.txtSiteName.SelLength = 0
Me.txtSiteName.SelStart = 50
Any ideas?