How can I get Access to stop selecting all the text in a text box???

Myrna Larson

Registered User.
Local time
Today, 03:00
Joined
Aug 3, 2012
Messages
16
Several years ago I designed a form for entering data in an Access 2003 database. It has event code and many VBA macro functions which work fine. (I was an Excel MVP years ago, one of the top posters in the VBA programming section, so VBA is not a problem for me.)

I am now updating this mdb database using Access 2010 (but it's still in mdb format).

The problem is that since I moved a particular text box from the main part of a form to the 2nd page of a tab Control, when I enter this text box, all text is selected. I want ONLY an insertion point.

The Client Setting for behavior on entering field is go to start of field. That should eliminate my problem, but it doesn't.

The data source the problem control is a Memo field. When this text box was on the main form, a macro for the Enter event set the selection start to 0 and the length to 0. (Actually I shouldn't need this, but I did.) I moved the Notes field to Page 1 of the Tab Control. It's the only field on that page.

Typically I want to edit fields on the 1st page of the tab control. I move through fields on the 1st page using the tab key. When I use the tab key to leave the last field on Page 0, I get to the Notes memo field on the Page 1, but ALL the text is selected :mad: !!! I have traced the code, and the Enter event macro does fire.

(Note that if the tab control is showing Page 1 and the Notes memo field when I leave the last field on the main part of the form, the tab key takes me to the Notes text box, and it has just an insertion point.)

For your information, I've copied the 2 event procedures below. Thanks for any help!

Private Sub DoHip_LostFocus()
'DoHip is the last control on the FIRST page of the tab control
' i.e. Page 0

'in fact this procedure seems to fire AFTER the Notes_Enter code

Me.tabControl.Pages(1).SetFocus
With Me.Notes
.SelStart = 0
.SelLength = 0
End With
End Sub

Private Sub Notes_Enter()
'Notes is the only control on the SECOND page of the tab control
' i.e. Page 1

With Me.Notes
.SelStart = 0
.SelLength = 0
End With
End Sub
 
Hi Myrna and welcome,
I've never found setting the focus to a Tab page very useful. I've always had to set it to the Control on the Tab to get the results for which I was looking.
 
Yes, that was just something I tried in desperation. It didn't make any difference. Modifying the code to what follows (the LostFocus procedure just sets focus to the text box on the next page) still results in the entire text being selected, i.e. the instructions in the Notes_Enter procedure seem to be ignored.

I wonder if this is just an outright bug?? (oh, sorry, I meant issue).

In any case, thanks for your reply.

Private Sub DoHip_LostFocus()
'DoHip is the last control on the 1st tab, i.e. Page 0
' Me.tabControl.Pages(1).SetFocus
' With me.notes
' .SetFocus
' .SelStart = 0
' .SelLength = 0
' End With
Me.Notes.SetFocus
End Sub

Private Sub Notes_Enter()
'Notes is the only control on the 2nd tab, i.e. Page 1
With Me.Notes
.SelStart = 0
.SelLength = 0
End With
End Sub
 
I noticed you are calling them Macros but displaying them as code. Are they code or Macros?
 
They are VBA code.

Where I come from, Excel, the term for VBA procedures is still macros. I forget that Access has macros, which are different from VBA procedures. Sorry.
 
Any chance you could post a sample db for me to play with? Remove any sensitive data of course. Compact and Repair and then zip it up for posting.
 
Just a quick suggestion. I've found that if certain form stuff doesn't work like it logically should, a DECOMPILE can sometimes fix the problem. I was looking at your code and all, and I don't see anything that logically should not work. So, maybe doing a Decompile and then compile again, might jar it back into shape?

Just thought I would pop in with that tidbit as it is quite off the path of the current troubleshooting.
 
Any chance you could post a sample db for me to play with? Remove any sensitive data of course. Compact and Repair and then zip it up for posting.

I'm not sure I want to take the time. It's medical information. I could, of course, update the names to something else (and the addresses, and the phone numbers, and the dates of birth, etc, etc).

Unfortunately there are also names (of relatives) and comments about who the person's parents are, etc, in the Notes field (i.e. the memo field) -- the one that's giving the problems.

PS: I see you were an Access MVP. I think I mentioned I was an Excel MVP. So Hi from another member of the (now extinct, I think) MS MVP program.
 
a DECOMPILE can sometimes fix the problem

Thanks for that tip. Excel VBA has the same problem with corruption. In fact Rob Bovey, one of the other Excel MVPs. wrote a utility to write all modules to disk, delete the code, save the XL file, then reimport the code.

I assumed Access had the same problem, but didn't know of the /decompile switch to handle it.

Anyway, I did open the file with that switch. I got an error message -- did I want to continue. I said Yes. Turns out that an entire module (one that writes the data out in a custom-formatted text file) was now blank. I have text-file backups of all the modules, so I reimported it.

BUT... of course none of this fixed the problem with the selection on entering the Notes field.
 
Last edited:
It isn't extinct. It is still going strong. And Allan is still an MVP (me, I'm a former as of July).

It's great to learn there are still some old cronies around! :):):)

So where are the MS forums these days? No longer newsgroups, I think. How do you get to them? Via the MS Office web site?
 
@Myrna: It is pretty easy to create a safe db. Start a New db and then *import* just what you need for the demo. On the Tables tab of the import dialog there is an "Options >>" button that allows you to only import the table structures and not the data. Then just dummy up at least one record so we can see the issue. BTW, this can sometimes clear up issues since it tends *not* to import any corruption.
 
@...only import the table structures and not the data. Then just dummy up at least one record so we can see the issue.


I'll give it a try. Thanks for the additional info. As you can probably tell, Access is not my thing -- something I dabble with for a 92 year-old friend, for this one research project.
 
Here's an mdb file which has just the 3 needed tables and the data entry query. The main table is named HS. It has just 1 dummy record. The form Data Entry runs when you open the file.

When I use the Tab key to move from the last control on the Medical Data page of the Tab Control to to the Notes control on the Notes tab, all text is selected. It shouldn't be. The Client settings are to put an insertion point at the start of the field when a control is entered. In addition, the Notes text box has an Enter event macro which is supposed to set the selection to just an insertion point at the beginning.

Good luck, and thanks for all the help!
 

Attachments

I see 4 people have looked at the mdb file. No comments or suggestions or solutions?
 
Sorry, I forgot to respond. I can't get it to work as you would like either. No clue as to why it does what it does. It is a mystery. But maybe you can do what I do sometimes. And that is create a form for editing it. It would pop up that form when you get to that text box and then it can be edited there using an unbound text box and then upon closing it replaces the contents in the box on the main form. (just a suggestion to overcome this irritating issue.)
 
In a way, I'm glad it doesn't work right for you, either. Reassures me that I'm not losing my mind. Thanks for the suggestion about another form. I'll have a look at that.
 
The global Client setting for "Behavior Entering Field", may not always be maintained.

I use the following function where I need to in the form code.

Public Sub SelField(p0All2End)
'p0All2End: 0 = Entrire Field, 1 = Start of Field, 2 = End Of field
Application.SetOption "Behavior Entering Field", p0All2End
End Sub

0 Selects all the field - to over type
1 Puts the cusor at the start of the field
2 Puts the cursor at the end of the field

Hope this helps you.

Alan :)
 

Users who are viewing this thread

Back
Top Bottom