Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Address Book

Status
Not open for further replies.

Christin97

Technical User
Jan 9, 2001
2
US
I am creating an address book using access 2000. On my form I am trying to figure out what buttons to use and how to get it to connect and bring up the addresses as the letters are clicked on. I want to put the alphabit on seperate buttons on the top of my form so that all you'd have to do to look up someone is click on the letter that represents that persons last name so it comes up on the form. Any help will be appreciated

thanks,
Christina
 
You could check out the Address form that is located on the Northwind sample database, but I don't like that example. I have a simpler approach. Create your form based on a query based on a table with fields such as LastName, FirstName, Phone, etc. Then on the form footer put Command buttons on your form for each letter of the alphabet. Cancel out the wizards that come up when you place a command button on your form. For the letter A, right-click the button and then go into your property sheet. Type &A for your caption property. Then you will have to write one line of code to apply the filter that will bring up the employees with Last Name of A. Go into your OnClick property and add this line of code.

Private Sub Command7_Click()
DoCmd.ApplyFilter Filter, "[LastName] Like 'A*'"
End Sub

Then just repeat it for each letter of the alphabet.
 
Christina,

Not difficult at all.

First create your tabular form from your address table.

We'll call your address table tblAddress if it's different from this then just substitute tblAddress with the actual name.

The Recordsource will be :

SELECT * FROM tblAddress;

Now create a command button for each letter of the alphabaet.

Copy the following function to your form code i.e. View code and control end to bottom and paste the function.

Public Function AddressSelect(strLetter As String) As String

AddressSelect = "SELECT * FROM tblAddress " & _
"WHERE Surname LIKE '" & strLetter & "*';"
End Function


Note if your field name for surname is not Surname then replace it accordingly.

Now behind each alpabet button put the code

Me.RecordSource = AddressSelect(Screen.ActiveControl.Captlion)
Me.Requery


And that's all there is to it! Good luck.
Bill Paton
william.paton@ubsw.com
Check out my website !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top