Code to use unknown fields in a table

C

Charlie

Hi, here is part of some code I have to access table fields. The trouble is,
I am constantly using different table of data, each with their own field
names. This is what my code currently does (one example):
Checks the "Home Phone" field to see if there is anything data there, then
if so it assigns this data to a string, along with an string that is called
"Home Phome". Is it possible to just have code where it will look through
the table's fields one by one and if there is data there then it will assign
it to a string and also asign the field name to a string that I can associate
with it. Thanks. This would be a big help, as everytime I use a different
table/data, I have to update the fields into a new table with correct field
names:
Dim rs As ADODB.Recordset
Dim cn As New ADODB.Connection


Set cn = CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open "NameSortQuery", cn, adOpenKeyset, adLockPessimistic, adCmdQuery


Do While Not rs.EOF

DoEvents
If rs("Home Phone") <> "" Then
strData = rs("Phone")
strDataID="Home Phone"
End If
....this is just part of the many fields I have to do. If there were a way
to have the code just take whatever field there were in a particular table it
would save me hours...
thanks,
Charlie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top