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

programatically get the first column

Status
Not open for further replies.

access97to2000

Programmer
Aug 12, 2002
45
US
Hi,
how can i programatically get the first column of a table ?

i need to write

for ex:

select column1 from table 1

Hereis what i want :
i want the last record id value of all the records and add 1 to it and insert a record in a table. IT is a generic function.
now what i am doing is:

sql=select * from table1;
rs.open sql,----
rs.movelast
value= rs(0)+1


i find it like a round about - because even though i dont want all the columns, i am retrieving them.. is there any way to get only the first column ?
 
Add this function to a module in your DB then call it in your SQL.


Function FirstColumn(strTableName As String)

FirstColumn = CurrentDb.TableDefs(strTableName).Fields(0).Name

End Function

Example...

SELECT
firstcolumn("TableName")
FROM
TableName;

 
hmmmmmmm,

why? (both the question and the response). the question as it obviously demonstrates the more or less complete lack of attempting to read any documentation, as well as relying on implementation details which are generally supposed to be irrevelant to developers at that level (e.g. what happens if 'others' tamper with the order of the fields?). the answer in as much as it is at least as limited as the question, and -in fact- fails to even provide a truly workable soloution to the problem as stated. (it does provide a method of retrieving the field name of hte 0th field -but only for the specified table- and does not provide the incremented value, or even return the current "max" value.

I am sure many will censure me for the long winded (soap box oratory) which does NOTHING to resolve any of the point which I am raising, but my intent is JUST to raise the issues, not to answer the question.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top