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

append field into access db error

Status
Not open for further replies.

WebStar

Programmer
May 1, 2002
69
DE
Hi,
I get an error (no. 3211) when I try to add a new field
into an access data base with the append method. This is the code:

Code:
Private Sub UpdateField(ByVal newFieldName As String)
Dim db As database
Dim td As TableDef
Dim fl As Field
Dim bFieldName As Boolean
db = ... to define
Code:
For Each fl In db.TableDefs("AllUsers").Fields
        If fl.Name = newFieldName Then
            bFieldExists = True
            Exit For
        End If
Next fl

If Not bFieldExists Then
        'create field
        Set td = db.TableDefs("AllUsers")
        If Not td.Updatable Then
            MsgBox "TableDef not Updatable! ", vbInformation, "Cannot update !"
            Exit Sub
        End If
        Set fl = td.CreateField(newFieldName, dbText)
        td.Fields.Append fl
<---error 3211
Code:
End If

End Sub
 
I've changed the code a little to be more general...

Code:
Private Sub UpdateField(ByVal newFieldName As String, ByRef db as Database, ByVal TableName as String)
Dim td As TableDef
Dim fl As Field
Dim bFieldName As Boolean
 
For Each fl In db.TableDefs(TableName).Fields
        If fl.Name = newFieldName Then
            bFieldExists = True
            Exit For
        End If
Next fl

If Not bFieldExists Then
        'create field
        Set td = db.TableDefs(TableName)
        If Not td.Updatable Then
            MsgBox &quot;TableDef not Updatable! &quot;, vbInformation, &quot;Cannot update !&quot;
            Exit Sub
        End If
        Set fl = td.CreateField(newFieldName, dbText)
        td.Fields.Append fl
<---error 3211
Code:
End If

End Sub

Anyone knows why I get this error? Thank you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top