Free Lessons
Courses
Seminars
TechHelp
Fast Tips
Templates
Topic Index
Forum
ABCD
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > TechHelp > Directory > Access > Ctrl-A Select Long Text < KeyDown | Global Status Fn >
Back to Ctrl-A Select Long Text    Comments List
Pinned    Upload Images   Link   Email  
Transcript
Richard Rost 
           
31 days ago
In today's video, we're going to learn how to use Control A to select all the text in a long text box based on a long text field in Microsoft Access. Today's question comes from Evelyn in Lumbard, Illinois, one of my platinum members. Evelyn says, "My database has long text fields that I use for entering and editing notes from my field text. In most applications, pressing Control A selects all the text in the current field or document, but in Access, it selects all the records instead. This is frustrating because I often want to quickly select all the text in a field while typing or editing so I can cut, copy, or paste it. How can I change this behavior so Control A works the way it does in other applications?"

That can be annoying. I've run into this myself in the past. Let me show everybody else what we're talking about. In most other applications like Microsoft Word, here's a Word document. If I hit Control A, it selects all the text. I can then copy, paste, whatever with it. In Excel, if I hit Control A, it selects everything. I can cut, copy, and paste. Even in Notepad, if I hit Control A, it selects all the text. I can cut, copy, and paste it.

If you want to read a cool story, we're warfin' Jetsia Huntsam Troubles. I'll pause now and read that. But in Microsoft Access, if you're in a form and you hit Control A, even if you're in this long text field, if you hit Control A, it actually selects all the records, all the text on all the records. If I hit Copy now, Control C, and I go back into Notepad, let's open up Notepad here, you open up a different window, and it pastes all the records. No, I don't want that.

So, what do I want to do here? Well, Evelyn is working with long text fields where she is working with reports and text. She wants to be able to, as she's typing, hit Control A and select all the text in that long text box, so she can then do stuff with it.

Before we get started, this is going to be a developer-level video. What does that mean? That means if you've never done any VBA programming before, go watch this video. It's about 20 minutes long. It'll teach you everything you need to know to get started. We are going to use the key down event to trap when the user hits Control A, so make sure you watch this video to understand how the key down event works. Make sure you understand how set focus works, and make sure you understand sel start and sel length.

To watch these videos, if you're not familiar with any of this stuff, they're all free, they're on my YouTube channel, they're on my website, go watch them and come on back. First thing I'm going to do real quick is I want to make this text box bigger just for the purposes of class. Let's make this a little bit larger like that so we've got some room to see our long text field.

There are some ways you could do this without programming. For example, if you're in here and you want to select all the text, you could shift-tab and then tab back into it, and then hit copy, Control C. That's one way to do it. You could hit Control Home and then Control Shift, and that'll select all the text. That's kind of hard though. You've got to remember all those keys.

You could even associate a label with this and then use the Alt trick. You could assign Alt A to it and then hitting Alt A will select all the text too. For example, let's say over here in "first name", right, with a label here, let's say I want to put an ampersand in front of N. Now, see how there's an underline under N? Alt N will now select that field. So you can come back in here and if I'm over here now and I go Alt N, it selects that field.

Those are all things you could do without programming, but Evelyn wants to be able to hit Control A and select all that text. So we need a little bit of programming to do that. First, let's do the easy thing. Let's make a button that'll do that first. I like to show things with buttons first. Drop a little button down here. Cancel the wizard. We'll call it Select Text Button.

A lot of times when I'm playing around with something first, even if it's not going to be in a button, I'll put it in a button just to get it to work. Then I'll move it where I want it because buttons are easy. I can avoid programming events and all kinds of crazy stuff. I'll just throw it in a button, put it on a menu, and that way you can make sure it's working. Let's go into the button code.

Now, I want to select all the text in that field. So first you go to the field: Notes.SetFocus. Then: Notes.SelStart = 0. That says put the cursor before the first character. If you didn't watch the sel start video, go watch that. Then we're going to select all the text by saying: Notes.SelLength = Len(Notes), whatever's in there.

You could also come up here and say: If IsNull(Notes) Then Exit Sub. Maybe put that after you move there. That way it'll put the cursor there either way, but if there's nothing in there, it won't bother doing any of that stuff. Save it, debug compile once in a while.

Now we'll come in here and I'll hit "Select Text". There you go. So now we've got a button that does it. You could even do the same thing with the button that I showed you before. You can put the ampersand in front of "S" in "Select Text". Now you can do Alt S, and that will select all that text. But Evelyn doesn't want Alt S; she wants Control A.

How do we do that? We're going to have to use the key down event to capture Control A. Go to Design View, into the events, and into the key down event. If you haven't watched the key down video, go watch it now. The key code for "A" is 65. The shift code for Control is 2. So: If KeyCode = 65 And Shift = 2 Then ' This is Control A has been pressed.

What are we going to do? Well, pretty much the same stuff from the button. Copy that over. Actually, we probably want our IsNull in here too, because if there is no code in here, we'll do that, exit out. When we're all done, we're going to set the KeyCode = 0. We're going to blank the keycode.

If any of this is unfamiliar, go watch the key down video. I literally covered this exact same thing—well, kind of. Save it, debug compile. Now, come in here. I'm typing, I'm typing, I'm typing, Control A—and there you go. It selects all that text for you instead of selecting everything.

You can even make Control A copy that text to the clipboard, saving you another keystroke if you want to. Just come in here, and then right there, say: DoCmd.RunCommand acCmdCopy. Right, that copies the selected item to the clipboard. Throw a Beep in there too. Save it, type it, I'm typing, I'm typing, Control A, and it's now in the clipboard. Test it. Go back to Notepad, read my story, and then paste. There's all that text that I just copied.

This is a practical application for all that key down stuff that we learn and sel start and sel length. And that's getting Access to do exactly what you want to do. The whole point of Access is to make your job easier. If you want it to behave a certain way, then do it: take those Legos and put them together and make the form listen to you. That's the whole point of building your own application in Access: the database does what you want it to do. You don't have to change the way you work to fit your software.

If you like stuff like this, I've got tons more developer classes on my website; come and check them out. I'm working on Developer 47 right now, so there are hundreds of hours of videos for you to learn. Stop by and join in the fun. But that's going to do it for your TechHelp video for today. I hope you learned something. Live long and prosper, my friends. I'll see you next time.



TOPICS:
Using Control A to select text in Access  
Difference in Control A behavior across apps  
Working with long text fields in Access  
Key Down event handling in Access  
Setting focus to a text field with VBA  
Using SelStart and SelLength in VBA  
Creating a button to automate text selection  
Using IsNull condition in VBA  
KeyDown event to capture Control A  
Copying text to clipboard using DoCmd.RunCommand  
Adding keyboard shortcuts with ampersand in labels

COMMERCIAL:
In today's video, we're going to learn how to make Control A select all text in a long text box in Microsoft Access, just like it does in other apps. Frustrated by Access selecting all records instead? We've got you covered! Learn to capture the Control A command using VBA key down events, involving key code handling with sel start, and sel length. We'll also show you how to make Control A copy text to the clipboard too. This developer-level tutorial is packed with practical tips, so get ready to make Access work for you. You'll find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.

This thread is now CLOSED. If you wish to comment, start a NEW discussion in Ctrl-A Select Long Text.
 

 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2025 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 1/23/2025 8:39:42 AM. PLT: 1s