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

SQL/Access - return field names when recordset.eof

Status
Not open for further replies.

AGP

Programmer
Sep 11, 2001
97
0
0
GB
Could anyone please tell me, whether it is possible to return the field names of an Access2000 database when their are no records in the table? many thanks.
 
Something like this


dim adoRS as new ADODB.Recordset
adoRS strSQL, strConn
MsgBox adoRS.Fields(0).Name
 
Or like this, using DAO:

Code:
Sub lstfieldNames(ByVal tblName As String)
'Returns names of fields in table tblName in current db

    Dim db As DAO.Database
    Dim fld As DAO.field
    
    Set db = CurrentDb()
    For Each fld In db.TableDefs(tblName).Fields
        Debug.Print fld.Name
    Next
End Sub
 
Yet another way, via SQL:

SELECT * FROM <TableName> WHERE 1=0

Store the results of this query in a recordset and you can loop through the fields to get their name. The good part is that this also works when there ARE records in the table - it will return an empty recordset with only the field names.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top