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!

Problem Creating Table with Properties using VBA

Status
Not open for further replies.

EddyLLC

Technical User
Mar 15, 2005
304
US
Following is a section of code I have put together from various sources (I have never used code to create a table). When the code gets to the line when I try to add properties to the field, ".Properties.Append tdfField1" I receive an Invalid Operation Error. Help will be greatly appreciated.

Sub Create_Table()
On Error GoTo Err_Table
Dim db As Database
Dim tdfNew As TableDef
Dim rs As Recordset
Dim tdfField1 As Field


RoutineError = "Create_Table"
Set dbLocal = CurrentDb()
stablename = "Table1"
DatabasePath = "C:\DataBase\Database1.mdb

Set db = OpenDatabase(DatabasePath)

' Create a new TableDef object.
Set tdfNew = db.CreateTableDef("Table1")

With tdfNew

'Add Field 1
Set tdfField1 = .CreateField("Field1", dbText, 50)
.Fields.Append tdfField1
.Properties.Append tdfField1.CreateProperty("Caption", dbText, "First Field")
.Properties.Append tdfField1.CreateProperty("Description", dbText, _
"This is Field 1")


' Append the new TableDef object to the database.
db.TableDefs.Append tdfNew
End With

Set db = Nothing
Set db = CurrentDb()
 
Question moved the the VBA Visual Basic for Applications (Microsoft) forum, thread707-1260162.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top