Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Microsoft Access > Check for field...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 30069 of 31576
Post > Topic >>

Check for field in tabledefs prior to append

by timmg <tmillsgroninger@[EMAIL PROTECTED] > Apr 22, 2008 at 02:11 PM

The following code works well except I can't think of an elegant way
of checking for the existance of the named field prior to creating
it.  Suggestions?

Public Sub pNewField()
'Add a new field to every table in the collection
Dim strSQL As String
Dim db As Database, tdf As TableDef, intI As Integer

    Set db = CurrentDb

    For intI = 0 To db.TableDefs.Count - 1
        Set tdf = db.TableDefs(intI)
        ' Skip system tables
        If Left(tdf.Name, 4) <> "MSys" Then
            tdf.Fields.Append tdf.CreateField("Source_tbl", dbText,
15)
            strSQL = "UPDATE [" & tdf.Name & "] SET Source_tbl = " _
                & "'" & tdf.Name & "';"
            DoCmd.SetWarnings False
                DoCmd.RunSQL strSQL
            DoCmd.SetWarnings True
        End If
     Next

End Sub

Thanks,

Tim Mills-Groninger
 




 3 Posts in Topic:
Check for field in tabledefs prior to append
timmg <tmillsgroninger  2008-04-22 14:11:20 
Re: Check for field in tabledefs prior to append
Tom van Stiphout <no.s  2008-04-22 22:27:41 
Re: Check for field in tabledefs prior to append
timmg <tmillsgroninger  2008-04-23 06:02:37 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 1:36:08 CST 2008.