PDA

Click to See Complete Forum and Search --> : Retreiving Field Names from a DB


razzaj
Aug 21st, 2000, 03:56 AM
Hi;
I was wondering how can one retreive Field name in a db (column name) (access or Sql) .
In clearer terms , suppose you have a DB with one or more tables... we are only interested in "TableX" ... which has
Z number of fields. I want to be able to retrieve those fields name
trough VB code ... thus having a progam that does the following :

- user provides table name and dB name
- Program returns :

" this table contains Z Fields "
" here are the fields names "
"field1"
"field2"
.... etc
any help would be greatly apreciated

Nina
Aug 21st, 2000, 05:57 AM
1.) open a recordset(rs) that contain all fields of your table

2.) rs.Fields.Count gives you the number of fields

3.) to get the fieldname use this:

For i = 0 To rs.Fields.Count - 1
Debug.Print rs.Fields(i).Name
Next i



hope this helps

[Edited by Nina on 08-21-2000 at 07:29 AM]

razzaj
Aug 21st, 2000, 06:12 AM
... I c .. but will that return to me the Value contained in this field of that record ... or The NAME of the Field in the TABLE ?? that is what I need ...
I need the Name Of the Field the Column name that is ...

Nina
Aug 21st, 2000, 06:31 AM
sorry, forgot to add the .name property...
now it will give you name of the field