Solved

ABCDEFGHI....Command Box's Lookup

Posted on 2001-08-31
11
240 Views
Last Modified: 2006-11-17
I need to have an Alphabetical Lookup Routine with
a Bar accross the top of the page.
A B C D    etc

The lookup up is a Access Database

I realise i can have a combo or list box doing this, and already have this working ok., but, i would also like to have the above as well.

Is there an easy way of doing this, without manually generating 26 command buttons  etc....

And also, having a common routine  eg (AlphaClicked), which will know which Button has been clicked, and then do the lookup.

Would appreciate some code to do the above.

Hope someone can give me some assistance.
0
Comment
Question by:kennedymr
  • 5
  • 2
  • 2
  • +2
11 Comments
 
LVL 1

Expert Comment

by:garrenb
ID: 6446433
Use a toolbar

Or

For a common routine use 26 command buttons in an array and use the .caption parameter to instigate the source of your query.

GarrenB
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6446642
Kennedy:

You can accomplish this by doing the following:

1) Add a button to your form
2) Name the button "cmdLetter" (without the quotes)
3) Set the caption of this new button to 'A'
4) Resize the button as desired
5) Position this button where you want it to be
6) Set the Index property of this button to 0 (zero)
7) Add the following line of code to your form's Load Event:

      SetUpLetterButtons

8) Add the following Subroutine to your form:

Private Sub SetUpLetterButtons()
   Dim idx   As Integer
   Dim Btn   As Control
   Dim Width As Single
   Dim Left  As Single

   With cmdLetter(0)
      Left = .Left
      Width = .Width
   End With

   For idx = 1 To 25
      Load cmdLetter(idx)
      With cmdLetter(idx)
         .Move Left + (idx * Width)
         .Caption = Chr(64 + idx)
         .Visible = True
      End With
   Next 'idx
End Sub


9) Add the following subroutine to your form:

Private Sub UnloadLetterButtons()
   Dim idx As Integer

   For idx = 1 To cmdLetter.UBound
      Unload cmdLetter(idx)
   Next 'idx
End Sub


10) Add the following line of code to your Form's Unload Event:

   UnloadLetterButtons



-Dennis Borg
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6446644
Small correction:

      >.Caption = Chr(64 + idx)

This really should read:

      .Caption = Chr(65 + idx)


-Dennis Borg
0
 

Accepted Solution

by:
GebhartBob earned 100 total points
ID: 6446653
    Here's a neat solution to your problem:

     1. Put a single command button on your, a little tiny one, with just the letter "A" on it. Put it exactly where you want the button to appear in the finished product. Set font, font size, bold, etc. for this "A" button, however you want all the buttons to look. The "A" button is the model for all 26 buttons. Call the button "cmdLetter" and set Index to 0, so it'll be considered an array by VB.

     2. Now write this simple little function and call it from Form_Load, setting LETTER_SPACING to the distance you want between buttons:

Private Sub createLetterButtons_Click()
   Const LETTER_SPACING As Integer = 100
   Dim i As Integer
   Dim leftPos As Integer

   leftPos = cmdLetter(0).left
   For i = 1 To 25
      leftPos = leftPos + cmdLetter(0).width + LETTER_SPACING
      Load cmdLetter(cmdLetter.UBound + 1)
      With cmdLetter(cmdLetter.UBound)
         .Caption = Chr(i + 65)
         .left = leftPos
         .Visible = True
      End With
   Next i
End Sub


     The command buttons will appear, all 26 of them, no problem. To respond to a user's selection of one of them, this is all you need:

Private Sub cmdLetter_Click(index As Integer)
   MsgBox "You clicked: " & cmdLetter(index).Caption
End Sub
0
 
LVL 15

Expert Comment

by:ameba
ID: 6446744
Manually generating 26 command buttons  is not big problem - if you have one control with index=0, you don't have to press 'Paste' 25 times, like:

    aaaaaaaaaaaaaaaaaaaaaaaaaa (I pressed 'a' only once :))

To position controls horizontally, use menu Format, Horizontal Spacing, Remove.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:kennedymr
ID: 6446782
Appreciate all the helpfull comments, very much.
Appreciate the help from dennisborg,also,this method works fine, as well.
Allways hard to work out who to give points with several working examples.!!!


Thanks again   Kennedymr
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6446959
I don't understand ... GebhartBob's solution was exactly the same as mine.
0
 

Expert Comment

by:GebhartBob
ID: 6446984
For DennisBorg---

     My solution was indeed exactly the same as yours, but I promise, it was arrived at completely independently. I didn't even know you had responded when I posted my answer. If there's a way to split the points, I'd be glad to.

---GebhartBob
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6447051
GebhartBob:

>but I promise, it was arrived at completely independently.

I am certain it was; I wasn't accusing you of cheating.

I was just surprised at the selected answer.



>If there's a way to split the points, I'd be glad to.

Nah, that's not necessary. I appreciate the offer though. I'm not really in it for the points.

It's not really a big deal to me, and I don't think it was intentional. I just don't understand why.



-Dennis Borg
0
 

Author Comment

by:kennedymr
ID: 6447418
Sorry to get in this position.
I did not notice the comments were so close in content.
How am i able to give some points to Dennis

Regards  Kennedymr
0
 
LVL 8

Expert Comment

by:DennisBorg
ID: 6448765
>Sorry to get in this position.
>I did not notice the comments were so close in content.
>How am i able to give some points to Dennis

Kennedy, don't worry about it. As I had said in my last post, it's not the points I was thinking about.

I just did not understand why it happened that way. I do not believe it was intentional on your part.

Regards,

-Dennis Borg
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb6 programatically bring window to front 8 63
How to create a duplicate finder Application 9 113
Add a task in Outlook from access 11 35
Child Form in front 4 34
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

948 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now