Query which selects fields?

BE19

cornfuzed
Local time
Today, 15:37
Joined
Mar 13, 2007
Messages
12
Is it possible to create a query which selects selects fields in a table, not just data in a field? If so, how?

TIA
 
I think you mean you want the field names from a table instead of the data itself. Not sure why you wouldn't just use the Documenter (Tools -> Analyze -> Documenter), but a straight-up query won't do this.

However, the TableDefs object will expose the field names. Make a button on a form and put this in that button's OnClick event:


Code:
    Dim FieldCount As Byte
    Dim strFields As String
    
    For FieldCount = 0 To (CurrentDb.TableDefs("YourTableName").Fields.Count - 1)
        strFields = strFields & CurrentDb.TableDefs("YourTableName").Fields(FieldCount).Name & vbCrLf
    Next
    
    MsgBox strFields

That will produce a list of fields and place them in a message box. There are other ways to do this (enumerating the fields collection for example), but this is straightforward and doesn't require knowing how to use a collection object.

From here, you can do whatever you want with each field name by changing where strFields stores each field name.
 

Users who are viewing this thread

Back
Top Bottom