How to access text property of a textbox? (1 Viewer)

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
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.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:16
Joined
May 21, 2018
Messages
6,371
I have a long discussion on that issue some where with a demo of that issue. I will see if I can find it. I assume that search box is in the header and it filter the form or a subform. When no record are returned by the search box even though you are typing in the search box some how it fires the event and then loses focus. Also you cannot set the focus back.
so adding
SearchRecIDList.setfocus
will not help.

Can you post an image or the actual database. It depends where the textbox is located. There are work arounds in design, but not in code.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:16
Joined
May 21, 2018
Messages
6,371
Here are some discussions of the same issue.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:16
Joined
May 21, 2018
Messages
6,371
Here is a demo. Type in something that returns no records "xx". It will throw that error.
My work around on search forms is to make the detail section a subform instead, but mainly I do not allow the user to type something that returns no records. I pop up a message that no records are returned and a roll the search back one letter. See second demo. This technique as seemed well liked by other developers using this code.
 

Attachments

  • FocusDemo.accdb
    848 KB · Views: 99
  • RollBack.accdb
    864 KB · Views: 170

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:16
Joined
May 21, 2018
Messages
6,371
If the OP is referring to the same issue I describe, this is not a bug but how Access works and it is a 100% repeatable issue. Rebuilding the form in the same way will not change the way Access works. The form has to be built different or at a minimum you cannot reference the textbox if no records are returned in the detail section after the change event.
 

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
Thanks for all replies.
While I'm reading the links and testing the given samples, seems that @MajP is hitting the nail on the head.

  1. The form is a search form.
  2. the text box is in the header.
  3. I open the form with "Select * FROM MyCrossTabQuary WHERE False". So there's no record set.
  4. If I first search the form with other fields and the form returns at least one record, I receive no error.
  5. My tests on other forms and databases where a bit different. They weren't search forms, the textbox was the only textbox in an unbound form and placed in the detailed section.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:16
Joined
May 7, 2009
Messages
16,408
there is also a fix.
know before hand if your filter will return any record.
if it will not do not filter, example:

s = me.search.text

'check if the textbox is not empty
if len(s)

sfilter = "[somfield] like "'* & s & "*'"

if dcount("1", "yourTableToFilter", sfilter) then
'there is at least a record to return
me.filter = sfilter
me.filteron=true
end if

else
'textbox is empty
'remove the filter
me.filteron = false
end if

''' i am using split form if that make any difference. i do not encounter your error about the .Text property.

you will only get "blank" form if you set Allow Additions to No on your form.
if the intension is prevent adding/editing record, you only set Allow Edits/Allow Deletions to No.
then Allow Additions = Yes.
to prevent adding record, you add code to the BeforeInsert event of the form:

private sub form_beforeInsert(cancel as integer)
cancel = true
end sub
 

Attachments

  • searchForm.accdb
    528 KB · Views: 144
Last edited:

SHANEMAC51

Active member
Local time
Today, 09:16
Joined
Jan 28, 2022
Messages
288
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 prefer filtering by all the main fields, and both by part of the value and by the interval, and not all fields for the filter can be set

at the same time, spaces, apostrophes, ampersands in text fields, different character styles (superscripts) are also processed

starting the filtering process by the button itself, as well as clearing the filter fields
 

Attachments

  • u_find0305.png
    u_find0305.png
    20.3 KB · Views: 158

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
there is also a fix.
.......
i do not encounter your error about the .Text property.
@arnelgp thanks for taking your time and going through this.
But I'm afraid your form structure is different with mine.
I changed your database a little bit.
Open the database and try to type something in the textbox in the header.
 

Attachments

  • searchForm.accdb
    788 KB · Views: 111

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
you will only get "blank" form if you set Allow Additions to No on your form.
if the intension is prevent adding/editing record, you only set Allow Edits/Allow Deletions to No.

Yes. If I set allow addition to Yes then That error message doesn't show up.
I have to talk with my supervisor for this change. Hope she agrees. And it won't be until next Tuesday. (3 days from now)

Meanwhile I'm looking forward to some other work arounds.
Apologies to @MajP I couldn't check his databases. This is Saturday evening here and I'm using a remote desktop connection to access my PC at office. I have a hard time with triple set up monitors at work and single monitor at home. I'll check it as soon as I'm back to work on Monday morning.

Thanks again to all members who responded.
 
Last edited:

SHANEMAC51

Active member
Local time
Today, 09:16
Joined
Jan 28, 2022
Messages
288
Open the database and try to type something in the textbox in the header.
IT WORKED when I removed all Arabic characters in the names of controls and sections of the form and recreated the search field, which by the way requires the full name of the company
 

Attachments

  • Screenshot_3.png
    Screenshot_3.png
    23.8 KB · Views: 165

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:16
Joined
May 7, 2009
Messages
16,408
Unfortunately setting Allow Additions To No on Continuous Form produces the error.
You will noticed that when there is "No Record"on the form, the RecordSelector to the Left
is reduced to small height (only you will see a Line).

i was not able to replicate the Recordselector "shrinking".
what i experiment is removing the RecordSelector.
but that has the effect of Labels "jumping" to left.
so i retain the record selector.

Also i toggle Allow Additions to Yes if there is No Record and No if there is at least a record to show.
open arnel_gp_Customers form.
 

Attachments

  • searchForm.accdb
    592 KB · Views: 150

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
IT WORKED when I removed all Arabic characters in the names of controls
Arabic character is irrelevant and they can't cause problem. Because I DON'T have Arabic character.
If removing Arabic character prevents error while reading .text property of the textbox, it's your lucky day.

thanks for the input.
 

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
i was not able to replicate the Recordselector "shrinking".
what i experiment is removing the RecordSelector.
but that has the effect of Labels "jumping" to left.
so i retain the record selector.
I'm not sure you're talking to me or not. Since I didn't mention record selector or difference in height.

Anyhow, I think we have a communicating problem here. You are working on the search and your OnChange event is just filtering the form.
I don't have any problem with filtering my form.
As my first post above, I need to read .text property of the textbox to RUN ANOTHER function and do something else. When I try to check myControl.Text I receive an error.
Show me how I can check if a user has typed + sign without receiving error and before textbox is updated. (On_Change OR On_Keydown OR On_KeyUp events.)

Thanks again.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:16
Joined
May 7, 2009
Messages
16,408
if you download the demo, yes it is filtering, therefore i can Get the .Text from
the search textbox and use it as my Filter, Even on NO records (showing).
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:16
Joined
May 7, 2009
Messages
16,408
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?)
 

KitaYama

Active member
Local time
Today, 15:16
Joined
Jan 6, 2022
Messages
442
if you download the demo, yes it is filtering, therefore i can Get the .Text from
the search textbox and use it as my Filter, Even on NO records (showing).
My apologies. I didn't noticed that.
I see you've set AllowAdditon to yes and then have hide all the textboxes.
I think I can use that.
Will test it on my database and will be back to you.

Thanks again.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 02:16
Joined
May 21, 2018
Messages
6,371
I am not sure where you are at with this current issue, and what problems still remain.
However, one simple solution for the original problem is to have an unbound form and a subform. The display looks pretty much identical. This never causes the original focus issue, since there is no "detail" records. I actually think this design has some advantages.
The demo shows both designs.
subform.jpg
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:16
Joined
May 7, 2009
Messages
16,408
there is no "subform" on your demo?
and the recordsource is Not a Blank recordset.

you need to use:

SELECT Products.* FROM Products WHERE (1=0);

as your recordsource.
 

Users who are viewing this thread

Top Bottom