Solved

arrow buttons

Posted on 1998-09-17
11
252 Views
Last Modified: 2010-04-30
VB5-DBList control - 2 cmdButtons on form - how do I program the 2 cmdButtons to act like the up and down arrow buttons to move through the list in the DBList control.
0
Comment
Question by:dstef
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
  • 2
11 Comments
 
LVL 3

Expert Comment

by:a111a111a111
ID: 1435391
Private Sub Form_Load()
    KeyPreview = True
End Sub

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
        Case vbKeyLeft: Label1.Caption = "Left"
        Case vbKeyRight: Label1.Caption = "Right"
        Case vbKeyUp: Label1.Caption = "up"
        Case vbKeyDown: Label1.Caption = "Down"
    End Select
End Sub

0
 

Expert Comment

by:sjrl
ID: 1435392
My understanding of your question is that you want to be able to navigate the DBList using the 2 buttons. I think the following will work.

The VB SendKeys command sends keystrokes to the active window. So providing the DBList is active, sendkeys should work. To achieve this try

Sub cmdUpButton
   DBList.Activate
   SendKeys "{UP}"
End Sub

similarly SendKeys "{DOWN}" for the down button
0
 

Author Comment

by:dstef
ID: 1435393
What should I substitute for Label1 and Caption in solution one? The Up button name is "cmdUP". The caption on this button is "UP".
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 3

Expert Comment

by:a111a111a111
ID: 1435394
It is just an example.
0
 

Expert Comment

by:sjrl
ID: 1435395
I think that either a111a111a111 or myself has misunderstood the question. The example given by a111a111a111 allows you to detect which keys have been pressed, whereas my example simulates pressing the keys. Which do you want dstef?
0
 

Author Comment

by:dstef
ID: 1435396
I want my cmdUP and cmdDown to simulate the up and down arrows
On the second suggestion (sjrl) the Activate caused an error message. Program didn't recognize this event or method. Did I leave something out?
0
 

Author Comment

by:dstef
ID: 1435397
I was not clear in stating the problem and a1112a111a111 thought that I wanted to determine what key was pressed. Thanks. sjrl is on the right track, but I still need something clarified. Awaiting reponse from him to my comment.
0
 

Author Comment

by:dstef
ID: 1435398
Problem solved. Thanks sjrl. SendKeys was the right answer, only needed to use DBList1.SetFocus instead of Activate. I don't know how to rate this since it is my first use of this service, but thanks again. Good job.
0
 

Accepted Solution

by:
sjrl earned 100 total points
ID: 1435399
I suggested the .Activate to ensure the DBList was the active control and therefore received the keystrokes. I think there is a way to do this, it maybe .SetFocus or something like that.

Hope this helps.

In order to rate my answer you need to have an answer from me. So here's an "answer" for you to rate.


0
 

Expert Comment

by:sjrl
ID: 1435400
My previous response was added before I got your comment (10:56)
I've had a few problems with getting comments out of sync.
Glad Setfocus worked!
0
 

Author Comment

by:dstef
ID: 1435401
Thanks again.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question