Solved

ABCDEFGHI....Command Box's Lookup

Posted on 2001-08-31
11
238 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

705 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

18 Experts available now in Live!

Get 1:1 Help Now