UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Place Table Field Names Into An Array, Any Version    
 
   
Larry Larsen
post Mar 25 2020, 11:57 AM
Post#1


UA Editor + Utterly Certified
Posts: 24,526
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi

Just tinkering around and I found myself up against a small wall..

I would like to populate an array with the field names from within a table..

Did a bit of searching and didn't really find any thing that I could either modify or use..

Would anybody here have a snippet of code or idea/link that I could use..

Appreciate your time..
Larry



--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
cheekybuddha
post Mar 25 2020, 12:08 PM
Post#2


UtterAccess Moderator
Posts: 12,620
Joined: 6-December 03
From: Telegraph Hill


Hi Larry,

Hope you're going OK in lockdown.

Do you really need the field names in an array. If you just need to loop them then would the TableDef.Fields collection be sufficient?

If you do require an array then you can use:
CODE
  Dim arrFields() As String, i As Integer, fld As DAO.Field

  With CurrentDb.TableDefs("YourTable").Fields
    ReDim arrFields(.Count - 1)
    For i = 0 To .Count -1
      arrFields(i) = .Item(i).Name
    Next i
  End With


Untested, but you get the idea.

hth,

d

--------------------


Regards,

David Marten
Go to the top of the page
 
MadPiet
post Mar 25 2020, 12:15 PM
Post#3



Posts: 3,565
Joined: 27-February 09



The fields collection, if you're using DAO, is essentially a zero-based array already. use the fields.Count property to get the number, then use that to dimension the array, then just loop through the fields collection, add the name to the array.
Go to the top of the page
 
Larry Larsen
post Mar 25 2020, 03:05 PM
Post#4


UA Editor + Utterly Certified
Posts: 24,526
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


Hi Guy's

Thanks that has helped me move on..
thumbup.gif

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    2nd April 2020 - 08:18 PM