Strange behaviour (1 Viewer)

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
i have used this code

http://www.access-programmers.co.uk/forums/showthread.php?t=188663

i contacted john to ask him why when using the search facility that when a lowercase 'i' is typed i get an error. i dont know if someone else has had this problem but you canovercome it by clicking end and continue typing. strange.

john did say that it sounds like it is something to do with windows auto correct.

any thoughts on how to solve this would be a great help.

i will state that when a uppercase 'I' is keyed it is ok.

thanks for any help
 

vbaInet

AWF VIP
Local time
Today, 20:43
Joined
Jan 22, 2010
Messages
26,374
Attach a stripped down version of your db and tell me how to reproduce the problem. I don't see why typing "i" would cause a problem.

Also, what is the exact error message?
 

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
sorry its taken so long but i messed up big time with my actual database. clicked save as and dont know what i did but a stripped down version ended up being the actual version. oops.

error - run-time error '2110'
microsoft access cant move the focus to the control search results

ive uploaded a stripped down version too.

all you have to do is open frmClientSearch

type a lower case i in the search bar at the top and let me know if you see the same error.

if not what could be the cause
 

Attachments

  • search-issue.accdb
    2 MB · Views: 205

Mr. B

"Doctor Access"
Local time
Today, 14:43
Joined
May 20, 2009
Messages
1,932
I tested your issue and yes, I got and error indicating that focus could not be moved to the search control. I don't know if that is the error you are talking about but I resolved that error by moving the line of code:
Code:
Me.SearchResults.SetFocus
to just before the End Sub and the error went away.
 

vbaInet

AWF VIP
Local time
Today, 20:43
Joined
Jan 22, 2010
Messages
26,374
I tested your issue and yes, I got and error indicating that focus could not be moved to the search control. I don't know if that is the error you are talking about but I resolved that error by moving the line of code:
Code:
Me.SearchResults.SetFocus
to just before the End Sub and the error went away.
Mr. B, is this related to JohnBigBooty's code? If it is it would be a good idea to let him know.
 

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
moving the line of code:
Code:
Me.SearchResults.SetFocus
to just before the End Sub and the error went away.
could you please let me know which Me.SearchResults.SetFocus you moved as there are 2.

i moved the second one down to where you said and it didnt like that at all. can you post the last bit of code. say where it changes so i can see please.
 

Mr. B

"Doctor Access"
Local time
Today, 14:43
Joined
May 20, 2009
Messages
1,932
Sorry it took me a while to get back to you. Been really busy.

Here is the code as it is after I made the change:
Code:
'Create a string (text) variable
    Dim vSearchString As String

'Populate the string variable with the text entered in the Text Box SearchFor
    vSearchString = SearchFor.Text

'Pass the value contained in the string variable to the hidden text box SrchText,
'that is used as the sear4ch criteria for the Query QRY_clientsearch
    SrchText.Value = vSearchString

'Requery the List Box to show the latest results for the text entered in Text Box SearchFor
    Me.SearchResults.Requery


'Tests for a trailing space and exits the sub routine at this point
'so as to preserve the trailing space, which would be lost if focus was shifted from Text Box SearchFor
    If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
        Exit Sub
    End If

'Set the focus on the first item in the list box
    Me.SearchResults = Me.SearchResults.ItemData(1)
    'Me.SearchResults.SetFocus

'Requery the form to refresh the content of any unbound text box that might be feeding off the record source of  the List Box
    DoCmd.Requery

'Returns the cursor to the the end of the text in Text Box SearchFor
    Me.SearchFor.SetFocus

    If Not IsNull(Len(Me.SearchFor)) Then
        Me.SearchFor.SelStart = Len(Me.SearchFor)
    End If
    
    Me.SearchResults.SetFocus

You really would not need two SetFocus statements. The last on should be all you need.
 

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
hi ive tried your code. it doesnt seem to be happy with multiple characters. say you want to search for bloggs. it searchs of the first character only. you type b it searches and disappears.

strange.
 

Mr. B

"Doctor Access"
Local time
Today, 14:43
Joined
May 20, 2009
Messages
1,932
Shultzy,

I have attached a modified version of your database. It will now keep the values you type in the Search text box and filter the records appropriately.

It now retains the characters you have typed and leaves the cursor at the end of the typed values.

There is also no issue with a lowercase "i" or an uppercase "I".
 

Attachments

  • search-issue.accdb
    808 KB · Views: 218

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
could you explain what has been one. just in case it happens in the future.

is it something to do with the database settings or the code?
 

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
dont worry ive seen it. its the code right? its a shame the original search thread is closed as this could be another addition.

thanks for your help mr. B
 

vbaInet

AWF VIP
Local time
Today, 20:43
Joined
Jan 22, 2010
Messages
26,374
dont worry ive seen it. its the code right? its a shame the original search thread is closed as this could be another addition.
What original search thread are you referring to?
 

vbaInet

AWF VIP
Local time
Today, 20:43
Joined
Jan 22, 2010
Messages
26,374
The thread is still active. Just send John Big Booty a private message with a link to this thread if you feel he will benefit from this.
 

shutzy

Registered User.
Local time
Today, 20:43
Joined
Sep 14, 2011
Messages
775
sorry i thought it was closed.

thanks will do that.
 

Mr. B

"Doctor Access"
Local time
Today, 14:43
Joined
May 20, 2009
Messages
1,932
The only things that I changed was the code. The primary issues were; (1) the "Docmd.Requiery" that was removing the values you would type into the search text box. and (2) I added the .Text when referring to the search text box because it is an unbound control.

I put comments in the code, identifying the changes I made and the reason why I made the change.

It looked to me that Big John's code was just fine. I think you just got a couple of this out of place. Most of the time, the order of the code is critical because you need things to occur in the correct order and at the right time.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 20:43
Joined
Sep 12, 2006
Messages
15,660
one thing that MIGHT cause a problem with stuff like this:

by default access is not case sensitive.

however there is a string option (option compare binary?) that will make comparisons case-sensitive. you may be using that inadvertently.
 

vbaInet

AWF VIP
Local time
Today, 20:43
Joined
Jan 22, 2010
Messages
26,374
That applies to the form module though and I believe shutzy is performing the comparison in a table.
 

Users who are viewing this thread

Top Bottom