Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / May 2007

Tip: Looking for answers? Try searching our database.

How to place cursor at the end following Setfocus?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
plh - 29 May 2007 14:02 GMT
Hello Everyone:
The following code works very well except that the user has to keep clicking the
end of the string in the text box in order to add to it.
What I am really after is that after each entry into the text box, the list
(it's a continuous forms type of view) is progressively narrowed down. I seem to
recall that there is a simple way to make the cursor position itself at the end
of the string, but I'll be damned if I can find it in the MS help at this point!

Private Sub txtFilter_Change()
Dim strSQL As String

   Debug.Print Me.txtFilter.Value

strSQL = "SELECT * FROM tblCustOrds WHERE COP LIKE '" & Me.txtFilter.Value &
"*'"

   Me.RecordSource = strSQL
   Me.txtFilter.SetFocus
   
   
End Sub

I also can't help but notice that on the first "shot",     Debug.Print
Me.txtFilter.Value shows up "" and so there is no filtering effect until the
second shot. It may be relevant that I also have an after update event:

Private Sub txtFilter_AfterUpdate()
   Call txtFilter_Change
End Sub

Any help will be greatly appreciated!
-plh

Signature

Where are we going and why am I in this HAND BASKET??

Scott McDaniel - 29 May 2007 14:15 GMT
>Hello Everyone:
>The following code works very well except that the user has to keep clicking the
[quoted text clipped - 3 lines]
>recall that there is a simple way to make the cursor position itself at the end
>of the string, but I'll be damned if I can find it in the MS help at this point!

Do you mean you want to set the Cursor location at the end of whatever is in txtFilter? If so, you can do this:

Me.txtFilter.SetFocus
Me.txtFilter.SelStart = Len(nz(Me.txtFilter, ""))

>Private Sub txtFilter_Change()
>Dim strSQL As String
[quoted text clipped - 20 lines]
>Any help will be greatly appreciated!
>-plh

Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
plh - 31 May 2007 18:13 GMT
[snip]

>Do you mean you want to set the Cursor location at the end of whatever is in
>txtFilter? If so, you can do this:
>
>Me.txtFilter.SetFocus
>Me.txtFilter.SelStart = Len(nz(Me.txtFilter, ""))

[snip]
>Scott McDaniel
>scott@takemeout_infotrakker.com
>www.infotrakker.com

Thank you, Scott, it did reset the position but now I have another problem:
Here is the new code:

Private Sub txtFilter_Change()
Dim strSQL As String

   Debug.Print Me.txtFilter.Value
   
strSQL = "SELECT * FROM tblCustOrds WHERE COP LIKE '" & Me.txtFilter.Value &
"*'"

   With Me
       .Refresh
       .RecordSource = strSQL
       .txtFilter.SetFocus
       On Error Resume Next
       .txtFilter.SelStart = Len(.txtFilter)
   End With
   
End Sub

strSQL does not contain the most recent entry into the text box, for example, if
the user types "1", nothing happens, because at that point strSQL contains
"SELECT * FROM tblCustOrds WHERE COP LIKE '*'". Then if the user types "2" so
that the text box says "12", strSQL contains "SELECT * FROM tblCustOrds WHERE
COP LIKE '1*'" so now it filters those records where the first digit is equal to
1. In other words, the filtering action always lags one step behind what the
user has entered into the box. Is there anything that will alleviate that
effect?

Thank You,
-plh

Signature

Where are we going and why am I in this HAND BASKET??

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.