Listbox from Access Database
-
I'm working on a program that is the front end for a database (Access). One of the fields in the data base is set up to use options set in the field's 'Row Source' during design of the database. (When viewing the records in Access it comes up as a list box) I am wondering how I can get the options for that field into my program without hardcoding them. I can get the option that is currently chosen for a record back, but I need to know how to get ALL the possible options for that field. I'm using ADODB objects to access the database. Any help or pointers in the right direction will be much appreciated. Quinn
-
I'm working on a program that is the front end for a database (Access). One of the fields in the data base is set up to use options set in the field's 'Row Source' during design of the database. (When viewing the records in Access it comes up as a list box) I am wondering how I can get the options for that field into my program without hardcoding them. I can get the option that is currently chosen for a record back, but I need to know how to get ALL the possible options for that field. I'm using ADODB objects to access the database. Any help or pointers in the right direction will be much appreciated. Quinn
If you are using the ADO object in your application, do a simple query:
Select [YourField] from [YourTable]
Once you have executed that SQL statement say when the form loads, you can add items with something like:
ListBox.Clear()
Do While Not adors.EOF
ListBox.Add(adors("[YourField]"))
LoopHTH Nick Parker
-
If you are using the ADO object in your application, do a simple query:
Select [YourField] from [YourTable]
Once you have executed that SQL statement say when the form loads, you can add items with something like:
ListBox.Clear()
Do While Not adors.EOF
ListBox.Add(adors("[YourField]"))
LoopHTH Nick Parker
That didn't work. Stoopid IE made me lose my reply and I'm too tired to type it again. In short, that will only return the one option that a row has as a value. If one of the options were never selected it wouldn't show up in the list box. :) Thx though. Anything else you can suggest? Quinn
-
That didn't work. Stoopid IE made me lose my reply and I'm too tired to type it again. In short, that will only return the one option that a row has as a value. If one of the options were never selected it wouldn't show up in the list box. :) Thx though. Anything else you can suggest? Quinn
Are you saying such as if someone were to hold down the shift key when clicking the mouse inside the listbox, thus selecting multiple items? Is your question on how to get the value of all those selected items? :confused: Nick Parker
-
That didn't work. Stoopid IE made me lose my reply and I'm too tired to type it again. In short, that will only return the one option that a row has as a value. If one of the options were never selected it wouldn't show up in the list box. :) Thx though. Anything else you can suggest? Quinn
I think if you alter Nick's query so it starts out as
SELECT DISTINCT ....
it should give you the values you need. James Simplicity Rules! -
I think if you alter Nick's query so it starts out as
SELECT DISTINCT ....
it should give you the values you need. James Simplicity Rules!Sorry James, but the SELECT DISTINCT change didn't help either. :( Nick: What I am needing is, in Access, when viewing a table it can be set up so that when you are entering data into the database directly that a list box will open for a particualr field and display the options that you can select for that field. Such as a 'Gender' Field. A list box will show the options 'No Answer', 'Male', 'Female' so you can choose one of those three options for the record. If in all the records for that table only 'No Answer' and 'Male' have been chosen, I need a way for my program to also recieve 'Female' to add to MY list box, so that it can be selected in my program. I hope that helps clarify what I am looking to do using ADODB. The actualy field I need to do this with isn't Gender, but it makes for an easy example, else I'd be hardcoding all the live long day. Thx again for the tries. :) Quinn