Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases 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 26th, 2006, 10:14 PM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Dynamic Combobox List

I am using VBA, not VB to generate dynamic combobox list. The three combobox list come from the three columns of a Access table by using SQL select DISTINCT....

Intension: After all the list are populated, user is able to select from one of the combobox. Once the user select the item, the list in the other two are changed according to the relationship in the Access table. Otherwise, the user could make the combination which does not exist in the database. Do you have any idea how to do this? 1) I was thinking of using first combo_change to control the list of other two, but it mess up the combobox list when I do combo.clear.

2) how to control the list of other two? Shall I still open the database to run SQL again?

Any thoughts are grateful. Thank you very much.

 
Old June 27th, 2006, 02:55 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

The SQL in Access is pretty well integrated into the sytem. You can put many things into your SQL that would not fly outside Access.

One thing you can do is put calls into the SQL of functions existing in modules in the DB:
Code:
SELECT MyFunc(tbl!Fld), tbl!Fld
FROM tbl;
The DB system is optimized so that if the function receives no arguments, or receives a constant, the function is run only once, and the answer is stored, being inserted into each row of the output.
But if the function receives a variable argument (such as the contents of a field), the function will be run once per row.
If you wrote a function that read the value of combo 1, you could then call that function from the WHERE clause of the query that is the rowsource for combo 2. (You could build in a default value of, say -1 for cases where combo 1 is empty.)
Then the Change event of combo one could run cboTwo.Requery.
This way, combo two tends to its own business (with a little help from a User-Defined function).
 
Old June 29th, 2006, 09:41 AM
Registered User
 
Join Date: Jun 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much, BrianWren, haven't got chance to try your method as I finally come up the solution of using code to generate Pivot table, and use the output to call other functions. Thanks again.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Combobox List Fill Range jani Access VBA 1 July 29th, 2008 05:04 PM
Dynamic combobox using DB ulash JSP Basics 0 August 29th, 2007 08:43 AM
list of values from postgresql to combobox zamir4eva Beginning PHP 1 January 3rd, 2007 11:29 PM
"Are you Sure" Before Dropping List in ComboBox lam2rw Excel VBA 2 September 22nd, 2006 06:57 AM
Combobox that shows what's not in its list Mitch Access 6 September 18th, 2003 11:00 AM





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