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

How to determine is a partuclar field exist in a table 1

Status
Not open for further replies.

maupiti

Programmer
Oct 27, 2003
240
US
Access 2003

The code below did not print out the name of the fields
in the table. The For Each was never executed.

///////////////////////////////////////////

Sub Determine_If_A_Field_Exist()

Dim Dbs As Database
Dim Table_Definition As TableDef
Dim fldLoop As Field

Set Dbs = CurrentDb
Set Table_Definition = Dbs.CreateTableDef("CrossTab")

Debug.Print "Properties of new Fields in " &
Table_Definition.Name

' Enumerate Fields collection to show the properties of
' the new Field objects.
For Each fldLoop In Table_Definition.Fields
Debug.Print " " & Table_Definition.Name
If Table_Definition![LV_1] = True Then
MsgBox "The field exist"
End If
Next fldLoop

Dbs.Close

End Sub
 
Sorry folks about the typo and the spelling error. I meant to ask

"How to determine IF a particular field exist in a table?
 
I don't know how to accomplish what you want, but the reason your FOR loop didn't execute is because fltLoop has no value.


Randy
 
You wanted something like this ?
Code:
Sub Determine_If_A_Field_Exist(strFieldName As String)
   Dim Dbs As Database
   Dim Table_Definition As TableDef
   Dim fldLoop As DAO.Field
   
   Set Dbs = CurrentDb
   For Each Table_Definition In Dbs.TableDefs
     For Each fldLoop In Table_Definition.Fields
       If fldLoop.Name = strFieldName Then
         Debug.Print strFieldName; " exists in " & Table_Definition.Name
         Exit For
       End If
     Next
   Next
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thank You PHV (MIS)for your help. You are a genius.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top