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 > Arrow Keys & Text Box < Date Not Working | Scroll Wheel & Continuous Forms >
Back to Arrow Keys & Text Box    Comments List
Transcript Pinned    Upload Images   Link   Email  
Richard Rost              
26 days ago
Today we're going to talk about using the arrow keys to move up and down, left and right, in your continuous forms, which I've talked about in previous videos. But in this one, we're going to talk about a special situation where you don't want that to happen if the user is down in the long text box in the form.

Butter. So let me explain. Today's question comes from Dylan in Lombard, Illinois, one of my platinum members. Dylan says, "I've been using the technique you demonstrated in the extended cut of the move up, down using keyboard, TechHelp video to move the focus in a continuous form using the arrow keys and it works great. However, I have a text box in the footer where I display notes for the customer. If the note is multi-line and I click in that text box, using the arrow keys moves me to the previous or next record, which is not what I want. Is there a way to tell Access not to process the arrow keys if I'm in that specific field?"

Yes, Dylan, we certainly can. But, so everyone else is on the same page, let me go through and explain exactly what that other video covers, and then we'll talk about how to fix it.

Now, this is the video that Dylan is talking about, my original TechHelp video, where I show you how to move up and down between the records using the keyboard instead of having to use the mouse and click or tap, tap, tap, tap, tap, tap. In the regular version, we create two buttons: a previous and a next button with Alt+P and Alt+N, so you can use the keyboard to go up and down. But, in order to do it with the arrow keys, you have to use some programming, and I cover that in the extended cut. That's what Dylan's talking about.

Now, once in a while, when I'm in a good mood, I like to sometimes share the extended cut stuff with everybody, because I like to give you a little taste of what the extended cuts have. Maybe prompt you into joining a little temptation, therefore, yeah, yeah. Oh, okay. All right. So first, let me show you how to do this today.

So, you know how you can use the arrow keys, left, right, up, down, to go between the different fields in a continuous form, just like an Excel spreadsheet. Then, Dylan, we'll talk about how to fix your problem.

If you have not watched this video yet, go watch it. This is going to be a developer video. What does that mean? Well, that means we are going to need some VBA programming. So, if you've never done any programming before in VBA, go watch this video. It'll get you started. Everything you need in about 20 minutes. All right. Go watch that, and then come on back.

All right. So, here I am in my TechHelp-free template. This is a free database you can download from my website if you want to. We're going to start fresh because the other database is about three years old, so it didn't have this cool customer list like this one with all these fields in it. All right.

So, normally, you use Tab or Shift+Tab to move back and forth, or you can use the arrow keys, the left and right arrow keys. All right. Depending on how you have it set up in Access. What do I mean by how you have it set up? Well, if you go to File Options, if you go to Client Settings, there's an option right here that says Continuous Form Record Navigation Keys.

Now, the default is none. But if you switch it to up and down and hit OK, now, when you open up your continuous form like this, you can use the arrow keys. I'm going down, down, up, up, up, up, left, right. You can use them to move between the different fields. And this is fine if you want to use this. But this will now be the behavior throughout the entire database. Every continuous form you have will behave like this.

So, if you don't want every continuous form to behave like that, then we have to use a little bit of code in order to get this effect. All right. So, I'm going to go ahead and turn that back off again: File Options, Client Settings, turn that back to none. That's the default setting. And they didn't use to have this option, by the way, years back in different versions, which is when I started using the code because they didn't have this option. And they added the option, which made the code kind of obsolete. But yeah, there's still lots of benefits to doing it with code too, because you can trap other keys instead of just the arrow keys, but that's a whole different video.

So anyways, here's how you do it. You go to your form, you go to Design View. The first thing you do is go to the Form Properties and come all the way to the bottom. See this property here called Key Preview? Turn that on. Set that to Yes. Essentially what that does is it says, OK, the form and the form's events can intercept the keystrokes before they go to the fields on the form. So that's why it's just a field that gets it. But now we're saying, OK, the form can intercept these first. So, in the Form Properties under Events find the Key Down event.

Where are we at? Here it is, On Key Down right there. OK, this is the guy that's going to get each keystroke and do something with it. OK, so dot, dot, dot will bring up your code builder. And in here, we have the Key Down event. Now the Key Down event gets the key code. The key code is the ASCII key character of what you pressed on the keyboard, but there's some VB constants we can use. I got a whole separate lesson on the Key Down event. It also gets whether or not the Shift, Ctrl, or Alt keys were pressed. OK.

We're going to say if the key code, the key you pressed, equals VB KeyDown. That's a special constant representing the down arrow key. Then DoCmd. What do we want to do? Go to record, comma, comma, acNext. Go to the next record. Else if... else if... I can't spell today... else if the key code equals, you guessed it, VB KeyUp, then DoCmd.GoToRecord, comma, comma, acPrevious. Right and then End If.

If it's any other key, ignore it. Continue on your merry way, send the key onward to the control that you're on, and if you type a "4" it will put the "4" in there. One more little thing we're going to do right up top: we're going to add an On Error Resume Next because if you're on the last record and you hit the down arrow key, it'll throw an error if it can't move to the next one. So we just put a little error handling in there.

Now save it, give it a good debug compile, make sure everything compiles, we're going to close it, close it, open her back up again. And now we can use the arrow keys. Right even if that property is set off because the Key Down event is intercepting our keystrokes. And again, you can use this technique with any other key on the keyboard you want. If you want to do something special when the user presses the "Q," then you can do it; you can just intercept it the same way.

Now, here's the problem. If you got a notes field down here, a text field, let me show you. Let's take the...let's steal the notes field off of the customer form. Alright, we got one already here, already built, already formatted. We'll just borrow this guy; it's the same field name, same table underneath it. Right, Design View, I'll click down here, and paste it. Alright, so here's a notes field. Very long text and let's pretend that... let's save this, close it, open her back up again.

Alright, let's put some stuff in here. Let's go to Jimmy Kirk, right. Alright. "T" is for type. Here is going to press Enter. Of course, this field has the "Enter Key is a new line in the field property" set, right because it's a long text. We'll just say, "This is line two, this is line three, another line, whatever." Now if I hit the up arrow at this point because I want to go up a line, it moves you up to the previous record. Because that Key Down event is intercepting the keystroke. So what we have to do is in our code say, OK, if you are in the notes field, don't do that. Or any other field you don't want it to do it in. How do we do that?

Well, we come over here, Design View, we go back to our code. So here's the Key Down event. Or you can...I have my little buttons up here on the Quick Launch toolbar. This is the one for View Code. I think it's on... which one? I don't know the one, I think it's over here. It's just easier to put up here. OK, so in here, after the On Error Resume Next but before the key strokes get handled, we're going to say, if I'm sitting in the notes field don't do it, exit out.

And that's if Screen.ActiveControl.Name = "Notes" then Exit Sub. So if you are sitting in the notes field, then beat it, don't run this stuff.

OK, you got it? Debug Compile. Close it down. Close it, save it, change it, close it, whatever. And now I can come up here and still do my thing. But if I come up to Jimmy Kirk and I come down here, I can still go up and down. Look at that. See, left and right, up and down, those key strokes don't get intercepted. That's pretty neat, right?

If you want to learn more about If Then and If Then Else, and all that stuff, check out this video. If you want to learn more about error handling, including that On Error Resume Next, go watch this guy. And if you like learning with me, if you have fun with my videos, and you want to learn more developer-type stuff, come check out the developer lessons on my website. I got tons, folks. I think I'm up to 45, just finished 45, which was customizing the ribbon and making right-click pop-up menus. I got tons and tons of developer lessons on my website. Check it out. Stop by and say hi, leave a comment, like and share, all that good stuff.

But that's going to be your TechHelp video for today. I hope you learned something. Live long and prosper, my friends. I'll see you next time.

TOPICS:
Using arrow keys to navigate continuous forms
Disabling arrow key navigation in specific fields
Setting up Continuous Form Record Navigation Keys
Enabling Key Preview for form interception
Using VBA to handle Key Down event
Programming arrow key navigation in VBA
Ignoring keystrokes in specific fields
Error handling with On Error Resume Next
Debugging and compiling VBA code

COMMERCIAL:
In today's video, we're tackling a unique challenge in Microsoft Access: using arrow keys to navigate in continuous forms while preventing unwanted record jumps when editing a multi-line text box. First, I'll cover how to set up basic arrow key navigation with VBA code. Then, I'll show you how to modify your code to avoid moving to the next or previous record when you're in a notes field, ensuring you can edit text without interruptions. Finally, I'll highlight error handling and conditional statements to refine this functionality. You'll find the complete video on my YouTube channel and on my website at the link shown. Live long and prosper my friends.
Add a Reply Upload an Image

 
 
 

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 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 10/13/2024 8:10:10 PM. PLT: 1s