How can you use down arrow key to scroll in a drop box?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DanicaDear
    Contributor
    • Sep 2009
    • 269

    How can you use down arrow key to scroll in a drop box?

    I have a QTY field and an ITEM field. User inputs a number into the QTY field, then tabs over the the next field and there's a down arrow on the right hand side of the field that you click to choose the correct item from the drop box. The combination of the QTY and the ITEM is the primary key (two primary keys). When I tab over to the ITEM field and press the down arrow, a message box pops up telling me that a primary key field can't be null (I suppose it's trying to go down to the next box rather than going through the drop down items). Is there an easy fix for this? I want to hit TAB key, DOWN KEY (multiple times to get through the drop box), TAB key (to get to the next QTY field). Thanks!!

    Missed you Bytes friends. Implementing the new DB...will be back in January with my next one. :-)
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    Hmm .... I think you might need to code that functionality into the "key down" event of the combo box in VBA.

    I could thow something together for you if you like. I encourage you to try it for youself first, though.

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      I can only replicate your problem by entering a QTY, tabbing into the Item Combobox, then Tabbing again, which is, as you said, trying to go to the next control. If you tab into the Combobox and use the mouse to drop down the box, everything works fine.

      What I'd do, simply to decrease the chance of hitting Tab twice and popping the error, would be to automatically drop down the box when entering it:
      Code:
      Private Sub ItemComboBoxName_GotFocus()
       ItemComboBoxName.Dropdown
      End Sub
      Linq ;0)>

      Comment

      • DanicaDear
        Contributor
        • Sep 2009
        • 269

        #4
        Ok, I was going to take Delerna's approach and try to come up with something myself....but I figured I was going to have to ask for a hint. Do you just need a good VBA book to learn what GotFocus() means, for example? My Access book has a chapter on VBA....but I'd need a listing of all the commands.... something more in depth.

        I haven't had a chance to try your idea Linq but it looks like that is the exact direction I want to go.

        Comment

        • missinglinq
          Recognized Expert Specialist
          • Nov 2006
          • 3533

          #5
          Here's a couple of sites that go into VBA:.

          Chrystal has an excellent “basics” tutorial:



          Jeff Conrad's resources page:



          Linq ;0)>

          Comment

          • Delerna
            Recognized Expert Top Contributor
            • Jan 2008
            • 1134

            #6
            Just a word of advice using got focus and lost focus events.

            Take care because your code can quite easily be sent crazy bouncing around the various got and lost focus handlers of your controls.

            Got focus of control1 and code in there causes control2 to get focus which cause lost focus of control1 to fire and code in got focus of control2 causes control1 to get focus.so got focus of control1 fires again as well lost focus of control2.

            It quickly becomes quite hairy.
            Try hard to use other events instead of got and lost focus wherever you can

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              Take care because your code can quite easily be sent crazy bouncing around the various got and lost focus handlers of your controls....

              Got focus of control1 and code in there causes control2 to get focus
              I'm sorry, but the code can't be sent bouncing any crazier than the scenario you presented! What possible reason would anyone have to place code in control1_GotFoc us to send the focus to control2, as you suggest?

              All events have to be used properly, paying attention to when they fire and exactly what triggers them, but making a statement like this about GotFocus and LostFocus is simply inane and gives a totally false impression!

              Linq ;0)>

              Comment

              • Delerna
                Recognized Expert Top Contributor
                • Jan 2008
                • 1134

                #8
                I was merely trying to illustrate a point and chose an over the top example to illustrate it.

                I have had experience debugging a database written by a colleague who found many inventive ways to use got and lost focus for many controls on the same form. The problem was that code written in other events caused the mentioned events to fire in unexpected ways, unexpected to my colleague that is, due to his inexperience at writing software. Indeed, I myself suffered the same experience when starting out. I found that inappropriate use of those 2 events in particular more troublesome, more difficult to get my mind around, more difficult to debug than any other.

                I certainly do not wish to give a false impression, just sharing my observations.
                Having said that,
                it certainly is true that
                All events have to be used properly, paying attention to when they fire and exactly what triggers them

                Comment

                • DanicaDear
                  Contributor
                  • Sep 2009
                  • 269

                  #9
                  As always, thanks for the thorough explanations. I'm always appreciative. I haven't grasped the whole GotFocus concept yet but I'm working on it. (I've been away from Access for awhile...which is not smart for me!)

                  Moving on....I got the GotFocus and .Dropdown as referenced above to work in the form. However, the form is a subform used on another form. It wouldn't work in the main form. (It just behaved as if the code weren't there at all, and the original problem is still my problem.) Any ideas why it works on the subform when it is opened all alone and not on the mainform that contains it?
                  Thanks in advance!
                  Danica

                  Comment

                  • Delerna
                    Recognized Expert Top Contributor
                    • Jan 2008
                    • 1134

                    #10
                    Hi Dancia
                    Have you tried putting breakpoints on the events coded in both the main form and the subform and then running your form and making the change. That way you can trace throught the sequence of events looking to see if things are happening as you expected. It is also a good method to learn which events fire and in what sequence they fire. Keep in mind that when your code stops at a breakpoint, you can hover your mouse pointer over variables and see their contents.

                    Breakpoints are also great for examining how a piece of code works even when there are no errors.
                    Just breakpoint every line of the code you want to examine, and the cause it to execute.
                    You can then watch the execution of the code, hover over variables/objects at each step and see how the code is changing them and all manner of useful things.
                    You can even drag the execution point to a different line,
                    change code on the fly, the list goes on and on.

                    Effective use of the debugger is the primary tool that will enable you to answer your own questions.....n ot that I am trying to discourage you from asking questions here.


                    Anyway, you will need to post the piece of code that you believe is at fault along with a clear desciption of what is happening.
                    I assume that
                    the original problem is still my problem
                    means
                    a message box pops up telling me that a primary key field can't be null
                    but you know what happens when you assume things.
                    My initial thought is that you are trying to move focus from the main form to the subform but a key field on the main form has not been filled in, but I am just guessing

                    Comment

                    • DanicaDear
                      Contributor
                      • Sep 2009
                      • 269

                      #11
                      Thanks Delerna. I am almost 100% confident I'm not using the dubugger appropriately because the only way it has helped me is by turning some of my text to a different color and alerting me of things that might not be right. I have a lot of work to do. (Will it ever end? No--that's why people have to retire!)

                      I'm glad you didn't assume because actually my problem is a little different, now that you mention it. When I am in the "Quantity" field, I enter a number. Then I tab over or hit the over arrow key, and the dropdown box DOES dropdown automatically. However, it does so VERY FAST (you can barely see it it's so fast) and then my cursor just sits in the combo box, as if the dropdown box never dropped down at all. So actually I do think the code is working...now the box just won't stay down. I need the box to stay down while I use the arrow keys to move through. However the box DOES stay down in the subform (when I open JUST the subform without the main form open). In reality, I would never open JUST the subform, only the main form. Note: the combo box doesn't drop down regardless of the main form being clean or dirty. I've tried both.

                      I'm posting my code here, just in case it helps.
                      Code:
                      Private Sub CommodityAndDescription_GotFocus()
                       CommodityAndDescription.Dropdown
                      End Sub
                      Note that this code is attached to the subform and doesn't show up in the VBA coding on the main form (which contains the subform). (I hope I'm not being too confusing but I'm not up on all the terminology like you experts.) I tried to add the code to the main form too but it didn't help.

                      Sorry for not explaining this correctly yesterday. I didn't realize the combo box was actually dropping down.

                      Thanks!

                      Comment

                      • Delerna
                        Recognized Expert Top Contributor
                        • Jan 2008
                        • 1134

                        #12
                        Hi Dancia
                        I just created a form with a textbox and a subform with a dropdown and put identical code on my subform for my dropdown and I can't replicate your problem. Everything works fine. So there is nothing to prevent you from achieving what you want to do. Something you have done is causing it and its not the code you posted.

                        Do you know how to set a breakpoint so that during exucution the debugger window pops up whenever that line of code gets executed?

                        Comment

                        • DanicaDear
                          Contributor
                          • Sep 2009
                          • 269

                          #13
                          I do not know how to do that yet...but let me investigate it before you try to tell me. I don't want to come across that I'm not putting forth the effort I need to. This will likely roll into next week for me, so I'll write back after I've tried to figure this out. I can put my DB on here if you think it will help. I'm totally done with it, except this problem (and really this is optional so if I can't get it I'll be disappointed but not non-operational.) LOL.

                          Comment

                          • Delerna
                            Recognized Expert Top Contributor
                            • Jan 2008
                            • 1134

                            #14
                            and really this is optional so if I can't get it I'll be disappointed but not non-operational
                            A Quality Manager once told me that building quality into a product that is over and above what the customer expects is just eating away at our own profits.

                            Sometimes we do that with software development. The extra time involved providing a feature is not worth the benefit gained. Not suggesting that I think this is the case with what you are trying to do here, I don't know your customer requirements. Just throwing it out there as something to keep in mind.

                            Comment

                            • DanicaDear
                              Contributor
                              • Sep 2009
                              • 269

                              #15
                              To other readers....Dele rna's solutions and points in this post are all excellent and valid. His code works, although I never got it working in my DB. I just decided it wasn't worth any more of my time. I may tackle it again in the future, but Delerna's final answer served me the best...at some point you just gotta move on!

                              Comment

                              Working...