Typing really fast run time error

vent

Registered User.
Local time
Today, 06:30
Joined
May 5, 2017
Messages
160
Hi everyone

So I'm working on an access database and I've saved two copies. One is read-only, the other is the copy I've been working on. They're both on the same drive, just in separate folders. I know this should be split, but for the time being I just copied this database for my supervisor to give brief demonstrations. However it was given to my attention that when one user wanted to use it they experienced this error:


Run time error '2185':

You can't reference a property or method for a control unless the control has a focus


And in the debug window this is what appears:

Code:
Option Compare Database
Option Explicit

Private Sub cmdReset_Click()
Me.txtSearch = ""
    Me.SrchText = ""
    DoCmd.Requery
    Me.txtSearch.SetFocus
End Sub

Private Sub Form_Load()
'DoCmd.Maximize
End Sub

Private Sub SrchText_AfterUpdate()
Me.SrchText.Requery
End Sub

Private Sub txtSearch_Change()
'Create a string (text) variable

    Dim vSearchString As String
    vSearchString = txtSearch.Text
    SrchText.Value = vSearchString
    If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
        Exit Sub
        End If
    'Me.SearchResults = Me.SearchResults.ItemData(1)
    
    'Me.SearchResults.SetFocus
    DoCmd.Requery
    Me.txtSearch.SetFocus
    If Not IsNull(Len(Me.txtSearch)) Then
        [B]Me.txtSearch.SelStart = Len(Me.txtSearch)[/B][B]//[I]THIS LINE IS HIGHLIGHTED YELLOW[/I][/B]
        End If
End Sub

My first thought was that this was an issue with conflicting versions of Access and maybe the user is using an older version. But when I opened up the read-only copy, I got the same error, even though my machine has a newer version of Access. I noticed that when I type really quickly I get this run time error on the read-only version, but whenever I type really fast on my version, I didn't get any errors. Even though the code is nearly identical

The only big difference is that:
Code:
Private Sub Form_Load()
'DoCmd.Maximize
End Sub

'DoCmd.Maximize is commented out on the read-only version. Other than that, the code is identical. Does anyone know why this is? Any feedback, always appreciated!
 
Last edited:
I don't understand the purpose of this code. The change event fires for every keystroke in the control, and it appears that in your problem code you are trying to set the insertion point to the last character DURING character entry. To me, it doesn't make sense to do this. If the user wants to enter a character in position 3 of a 5 character string, why not let her?

My suggestion is don't try and set SelStart during the Change event.

hth
Mark
 
I don't understand the purpose of this code. The change event fires for every keystroke in the control, and it appears that in your problem code you are trying to set the insertion point to the last character DURING character entry. To me, it doesn't make sense to do this. If the user wants to enter a character in position 3 of a 5 character string, why not let her?

My suggestion is don't try and set SelStart during the Change event.

hth
Mark

Well that's the thing right. I mean, I don't fully understand this as well but I just basically found this online, made some changes until it did what I wanted it to do. It works perfectly fine on my version of Access, I type really fast, really long things and I don't get any errors, but for some reason, it crashes in the read-only version, whenever I type really quickly. I saved another copy of what I'm working on but put it in a separate folder. Same thing, works like a charm so I'm considering, deleting the present read-only file and replacing it with this new copy
 
Last edited:
Try and just comment out that line of code...
See if that solves it.
Mark
 
Try and just comment out that line of code...
See if that solves it.
Mark

It didn't but I will just delete it and replace it with another copy. I also work on splitting this database. Thank you.
 
Vent,

I've had to work on something similar in the past. For me, when the field gained focus I'd set a timer. When it lost focus it turns the timer off.

In the timer, I have code like this;
Code:
IF me.TxtSearch <> as_Search
   as_Search = me.TxtSearch
else
   Lookup code based on me.TxtSearch
End If

The timer is normally set to either a half second or a second. This means that as the user types it doesn't trip but waits slightly until they are done. For large data sets this can dramatically improve how users view your system as they don't see a lot of "Flashing" nor a slow down as they start typing when the data requeries.
 
It didn't but I will just delete it and replace it with another copy. I also work on splitting this database. Thank you.
What code line did highlight in yellow then, because it can't be the code line you comment out!
 

Users who are viewing this thread

Back
Top Bottom