Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 1st, 2009, 03:49 AM
Registered User
 
Join Date: May 2009
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Default [help] search for record

my access file have a form that allow user to key in the customer account number,
and after that i want the customer name to be display in a listbox.
but the prob is, the records contain not only a account number and same account number may have different customer name.
what method should i use?

i totally no idea with it coz last time i only doin excel VBA..><

thank you in advance for the help
 
Old June 5th, 2009, 11:02 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

It sounds like you will have to give the users a method to look up a Customer Number (combo?) and then display all the possible Customer Names in your list box.

I would use the combo wizard to create a combo box that looks up the Customer Number. Then make sure there is no PK associated with the Customer Number (really, this is a design flaw with the database. There should be no dupes on the customer number, and one name associated with each number.)

So you combo might have:

Code:
SELECT DISTINCT CustomerTable.CustomerNumber FROM CustomerTable ORDER BY CustomerTable.CustomerNumber
Column Count 1
Column Width 2"
Bound Column 1


Then on the After Update event of your combo box:
Code:
Dim sCustNum As String
Dim sSQL As String
 
sCustNum = Me.cboCustomerNumber
 
sSQL = "SELECT CustomerID, CustomerName FROM CustomerTable WHERE CustomerNumber = '" & sCustNum & "'"
 
Me.lstCustName.RowSource = sSQL
Make sure the List box is set up to take Table/Query as the Row Source,
Column Count 2
Bound Column 1
Column Width 0";2"
Multi Select None

Then you will want to use the list box and a button to launch the results.

Did that help?
__________________
mmcdonal

Look it up at: http://wrox.books24x7.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search for a record using a form a_wahab Access 6 September 1st, 2006 12:03 PM
How do you open a specific record from a search? Szimmer9 VB How-To 1 March 31st, 2006 12:57 AM
search for duplicates before storing new record phytcmg Access VBA 3 April 1st, 2005 11:30 AM
code to search a record Rudner VB Databases Basics 1 November 17th, 2004 11:52 PM
How to search for (and select) a record? Haroldd Access 2 June 30th, 2003 06:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.