Solved

ABCDEFGHI....Command Box's Lookup

Posted on 2001-08-31
11
242 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
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.

 

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
 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
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…

821 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