Run-time error '2185'

OldBirdman

Registered User.
Local time
Today, 07:56
Joined
Jul 14, 2008
Messages
15
Run-time error '2185'
You can't reference a property or method for a control unless the control has the focus.
Code:
Private Sub txtName_Change()
    strSaveText = Me.txtName.Text
End Sub
The message occurs for Me.txtName.Text and only if the body of the form contains zero records. What's wrong?
 
The Change event occurs at every keystroke in a control. What are you attempting to achieve? You might want to use the .Value property instead of the .Text property.
 
Hi There OldBirdman,
Sounds like a null value. What is it you are trying to achieve? The .value contains the last saved value of the field where the .text is the currently unsaved content of the field with the focus. The VB help for "Text Property" would be a help I think?

Hope this is some use

:)

Q
 
My goal is to build an SQL statement to assign into the form's RecordSource property.
I want to type into a textbox, then have a command "Apply Filter" that does:
Me.RecordSource = "SELECT . . . WHERE . . . Like """ & txtName & "*"""
If txtName = "Ken", the names Ken and Kenneth are found. But if txtName = "Ken ", Access removes the trailing blank when the control txtName is saved on exit. I want only the name Ken to be found.
My current code is designed to save the current text as typed. When the filter command is pressed, strSaveName is used, not the value Access has saved, which is stripped of trailing blanks.
Code:
Dim strSaveName As String
. . .
Private Sub txtName_Change()
    Me.txtName.SetFocus 'I tried this to see if error goes away.  It doesn't!
    strSaveName = Me.txtName.Text
End Sub
I have tried OnExit, OnLostFocus, and BeforeUpdate, but it is too late by the time these events are triggered.
Note that this works as expected for a while. If "Ken " (2 trailing blanks) is used, there are no records found, and the detail section of the form is blank. Then txtName apparently cannot get the focus.
 
Have you tried to change the sql to remove the like? that way when you search for Ken then only Ken and not Kenneth should come up!

Hope I didn't miss the point
Cheers
 
I think you missed the point. Once the RecordSource query returns zero records, the program stops functioning correctly. Even though the control is unbound and should not be affected by the query, apparently it is.

Zero records is, however, a valid result. I need some way to show a blank detail section if zero records is the result without messing up the textbox in the Form Footer. I can know that I have zero records before the Me.RecordSource assignment, but I don't know what else to do to display nothing.

Thanks for considering my problem.
 
Ah right, how about doing a check if the recordset.recordcount = 0 then show a messagebox and display either the last filter or a standard sql statement. I hope that helps
 
Still the question from above, "I can know that I have zero records before the Me.RecordSource assignment, but I don't know what else to do to display nothing."
What standard SQL will display nothing? I can change the .Visible of all controls to False if zero records, and leave the RecordSource unchanged. Seems like a lot of code.
 
See my post of 10:42 AM Today (19 Jul08). Yes, me.recordsource = "" shows zero records, but it won't allow entry into the textbox either.
 
this is pretty bizarre. are you saying txtName is unbound? could it have something to do with being in the footer? seems the footer sometimes acts strangely. just a thought. also, in post #4 it sounds like everything is working until right after the code. suddenly you mention errors and you lost me... so, does the sql work? if it isn't, what if you deal with the string before it gets to the sql...i think i would use two diff sql stmnts one to deal with "*" another without.

(p.s. i'm not too sure which post you're talking about. i'm in a different time and date zone here and none of the times match what you said. use the post # near the top right).
 
I'm new here, didn't notice the post #'s. It is #6.

I'm going to upload a sample of the problem. To test:
1) Enter "Ken" in the box in the footer and press "Apply Filter". 2 Records are shown.
2) Enter "Kenn" in the box, press "Apply Filter". 1 record is shown.
3) Enter "Kennn" in the box & press "Apply Filter". No records are shown, which is correct.
4) Try typing in the box. Run-time error '2185' occurs.
 

Attachments

i did all of those birdman, I didn't get an error.

Just letting you know... ;)
 
Interesting - Access 2000/2007, Windows XP Home on desktop, Access 2002, Windows XP Home on laptop. Access 2007 doesn't give same error, it clears the textbox and locks it. Can't type, so no error.
 
I am trying to have a program that does not lock up or give an error if my pseudo-filter does not return any rows. But apparently a bound form cannot work if there are no rows, even if the control is unbound.
 
Hmmm....
Code:
If Me.Recordset.RecordCount = 0 Then 
   Me.RecordSource = "SELECT * FROM [COLOR="Red"][I]yourTable[/I][/COLOR] WHERE [I][COLOR="Red"]TableIDFieldName[/COLOR][/I] = 0;"
End if

:D
 

Users who are viewing this thread

Back
Top Bottom