How to access text property of a textbox?

KitaYama

Well-known member
Local time
Today, 10:15
Joined
Jan 6, 2022
Messages
1,885
I'm trying to check if a user has typed a + sign in an unbound multi line text box or not. If yes, I will run a function to do some specific actions.
I've tested with OnKeyDown, OnKeyUp & OnChange events. And receive the same error message in each case.
Access keeps telling me (if I understand well) that for accessing text property, the control should have the focus.

If I'm typing in a textbox, it means the textbox has the focus. Why Access keeps throwing the same Error over and over.
To narrow down what is causing the error, I deleted everything and added just two lines. (following image).

Still the same :

2022-03-05_09-08-46.png


To check if the control has the focus, I added the first line. Immediate window tells me the focus is on the same textbox.

1- I've decompiled/Recompiled several times.
2- I've compact & repaired.
3- I've replaced the line in problem with Screen.ActiveControl.text and still receive the same error message.
4- If I copy and paste the same textbox to another form or another database, the code runs successfully. No error message.

What are my options?
Thanks for your time, help and any kind of advice.
 
I see you've set AllowAdditon to yes and then have hide all the textboxes.
I think I can use that.
yes i am toggling it.
When there is No Record, Allow Additions = Yes., but Hide all textbox (controls).
When there is 1 or more records, Allow Additions = No, show all textbox.
This will eliminate the Error, when you try to get the .Text of the textbox.

As I said the Error occurs When there is no record and Allow Additions is Set to No.
 
@MajP
thanks for your help.
I'm checking your sample databases in #4, but it seems there's no sub form in the main form. maybe it's because of this damn remote desktop app.
But I can understand the concept you explained.
I'll try it when I'm back in office.

Again thanks
 
tell me, upon seeing there is a "+" sign on the .Text, what next is the pseudocode to do?
then i will make a Real working example (not the search form, but on post#7 you said it is a search form?)
I really appreciate your offer. But I think I can manage that as far as I can read .text property without error.

If you're curious :
The textbox is multi line. Users can type
A
F
G
and filter the form. They receive the result for : Field=A Or Field=F Or Filed=G

Now I'm adding a new feature to search. If the user type :
A+C
H
V+Z

the result would be : Field Between (A & C) OR Field=H Or Field Between (V & Z)

Of Course this is a single letter. In fact there are 8 different search fields for searching different fields with different data types

As I explained I can manage the search. I had problem with the error message. And for now it seems that's OK.

million thanks again...
 
Last edited:
there is no "subform" on your demo?
and the recordsource is Not a Blank recordset
Thanks that was the wrong file. In the version without the subform type in something that returns no records like "zz". This will throw the error. Then you can do the same in the form with the subform and not get the error.
 

Attachments

Users who are viewing this thread

Back
Top Bottom