[AccessD] Cheecking field exists

Gustav Brock Gustav at cactus.dk
Thu May 18 10:42:54 CDT 2006


Hi Martin

Here's a function we use (DAO):

Public Function IsField( _
  ByVal strTable As String, _
  ByVal strField As String) _
  As Boolean

  Dim dbs       As Database
  Dim tdf       As TableDef
  
  Dim lngCount  As Long
  Dim booFound  As Boolean
     
  On Error GoTo Fejl_IsField
  
  Set dbs = CurrentDb()
  Set tdf = dbs.TableDefs(strTable)
  
  lngCount = tdf.Fields.Count
  While lngCount > 0 And Not booFound
    booFound = (StrComp(tdf.Fields(lngCount - 1).Name, strField, vbTextCompare) = 0)
    lngCount = lngCount - 1
  Wend
  
  Set tdf = Nothing
  Set dbs = Nothing
  
  IsField = booFound

Exit_IsField:
  Exit Function

Fejl_IsField:
  IsField = False
  Resume Exit_IsField

End Function

/gustav

>>> mwp.reid at qub.ac.uk 18-05-2006 17:13 >>>
Is there an easy way to check if a field exists in a particular table vai vba?
 
Maritn
 
Martin WP Reid
Training and Assessment Unit
Riddle Hall
Belfast
 
tel: 02890 974477





More information about the AccessD mailing list