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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Selecting Specific Fields From A Table 2

Status
Not open for further replies.

Hackster

Programmer
Mar 28, 2001
173
US
I want to display fields from an Oracle table in a dropdown combo box. I'm doing a SELECT * FROM the table name, and then populating the combo box as follows: (Where FieldsRs is my recordset object)

Dim i As Integer
Dim iFieldCount As Integer
iFieldCount = FieldsRs.Fields.Count
For i = 0 to iFieldCount - 1
cboStationRef.AddItem FieldsRs.Fields(i).Name
Next

This does a sterling job of populating my combo box with all the fields in the table, however, I don't want ALL the fields. There are 98 fields in the table names Attrib01 through Attrib99. There are 21 other field names in this table that I don't want in the combo box. I don't want to build an SQL statement that does a SELECT Attrib01, Attrib02, Attrib03, etc through Attrib99 because, in all likelihood, more attribute fields will be added, and I want my code to accommodate them without having to make any coding changes. Finding the index of each combo box item won't do any long-term good in so far as the index for each item will change as the fields in the table change. Any suggestions?
 
If the table changes you generally have to change the programme anyway. However, you could put the field names you want in an ini file and get the programme to read them from that. Then you just have to change the ini file. Peter Meachem
peter@accuflight.com
 
Hmmm... Sounds to me like you should look over your table strukture and see if you can't break out the attribs for each item into a separate table. Then you also could add a field to that table indicating if you should display that field or not.

Like this:
Code:
ItemTable    ItemAttribTable
===========  ===============
ItemId (PK)->ItemId (FK)
ItemName     ItemAttribId (PK)
...          ItemAttribName
             ItemAttribValue
             ItemAttribDisplay

Good Luck!
-Mats Hulten
 
Thanks Matt. Based on your suggestion, I created a table in the local Access 2000 database that is deployed with my application, and dumped the field names to a table there. Then, doing a SELECT fieldname FROM localtablename WHERE fieldname LIKE 'ATT*' gets me all the fields that I want in a recordset that I, in turn, dump to my combo box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top