Hi All,
I have some code in a sub:
On Error Resume Next
DoCmd.RunSQL "DROP TABLE tblParcels" 'This deletes the table if it already exists.
Dim tblParcels As TableDef 'Create the table
Set tblParcels = db.CreateTableDef("tblParcels") 'Define the table
Dim fldURN As Field 'Create each of the fields
Dim fldSBI As Field
Dim fldTransSBI As Field
Dim fldWorkCat As Field
Dim fldException As Field
Dim fldLeaseEndDate As Field
Dim fldParcel As Field
Dim fldVFD As Field
Dim fldID As Field
Set fldURN = tblParcels.CreateField("URN", dbText, 10) 'Define each of the fields
Set fldSBI = tblParcels.CreateField("SBI", dbText, 9)
Set fldTransSBI = tblParcels.CreateField("TransSBI", dbText, 9)
Set fldLeaseEndDate = tblParcels.CreateField("LeaseEndDate", dbDate, 10)
Set fldParcel = tblParcels.CreateField("Parcel", dbText, 50)
Set fldVFD = tblParcels.CreateField("VFD", dbText, 12)
Set fldID = tblParcels.CreateField("ID", dbLong)
Set fldWorkCat = tblParcels.CreateField("WorkCat", dbText, 50)
Set fldException = tblParcels.CreateField("Exception", dbText, 50)
tblParcels.Fields.Append fldID
tblParcels.Fields.Append fldParcel 'Add each field to the table
tblParcels.Fields.Append fldVFD
tblParcels.Fields.Append fldURN
tblParcels.Fields.Append fldSBI
tblParcels.Fields.Append fldTransSBI
tblParcels.Fields.Append fldLeaseEndDate
tblParcels.Fields.Append fldWorkCat
tblParcels.Fields.Append fldException
db.TableDefs.Append tblParcels 'Add the table to the database
db is the current database, and this code works fine, in that it creates a table called tblParcels with all the fields named above.
However, I'm trying to use what seems like exactly the same logic to create a different table in another sub, and the table isn't being created:
On Error Resume Next
DoCmd.RunSQL "DROP TABLE tblNonRLE" 'This deletes the table if it already exists.
Dim tblNonRLE As TableDef 'Create the table
Set tblNonRLE = db.CreateTableDef("tblNonRLE") 'Define the table
Dim fldID As Field
Dim fldTemplate As Field 'Create each of the fields
Dim fldURN As Field
Dim fldSBI As Field
Dim fldSheetRef As Field
Dim fldParcelRef As Field
Dim fldArea As Field
Set fldID = tblNonRLE.CreateField("ID", dbLong)
Set fldTemplate = tblNonRLE.CreateField("Template", dbText, 6)
Set fldURN = tblNonRLE.CreateField("URN", dbText, 10)
Set fldSBI = tblNonRLE.CreateField("SBI", dbText, 9)
Set fldSheetRef = tblNonRLE.CreateField("SheetRef", dbText, 6)
Set fldParcelRef = tblNonRLE.CreateField("ParcelRef", dbText, 4)
Set fldArea = tblNonRLE.CreateField("Template", dbText, 8)
tblNonRLE.Fields.Append fldID
tblNonRLE.Fields.Append fldTemplate
tblNonRLE.Fields.Append fldURN
tblNonRLE.Fields.Append fldSBI
tblNonRLE.Fields.Append fldSheetRef
tblNonRLE.Fields.Append fldParcelRef
tblNonRLE.Fields.Append fldArea
db.TableDefs.Append tblNonRLE 'Add the table to the database
I don't get an error message, but the table doesn't get created. This is my third post in the week since I started playing with VB - and I know I may be missing something silly, but you've been helpful so far so any thoughts would be welcome!
thanks
I have some code in a sub:
On Error Resume Next
DoCmd.RunSQL "DROP TABLE tblParcels" 'This deletes the table if it already exists.
Dim tblParcels As TableDef 'Create the table
Set tblParcels = db.CreateTableDef("tblParcels") 'Define the table
Dim fldURN As Field 'Create each of the fields
Dim fldSBI As Field
Dim fldTransSBI As Field
Dim fldWorkCat As Field
Dim fldException As Field
Dim fldLeaseEndDate As Field
Dim fldParcel As Field
Dim fldVFD As Field
Dim fldID As Field
Set fldURN = tblParcels.CreateField("URN", dbText, 10) 'Define each of the fields
Set fldSBI = tblParcels.CreateField("SBI", dbText, 9)
Set fldTransSBI = tblParcels.CreateField("TransSBI", dbText, 9)
Set fldLeaseEndDate = tblParcels.CreateField("LeaseEndDate", dbDate, 10)
Set fldParcel = tblParcels.CreateField("Parcel", dbText, 50)
Set fldVFD = tblParcels.CreateField("VFD", dbText, 12)
Set fldID = tblParcels.CreateField("ID", dbLong)
Set fldWorkCat = tblParcels.CreateField("WorkCat", dbText, 50)
Set fldException = tblParcels.CreateField("Exception", dbText, 50)
tblParcels.Fields.Append fldID
tblParcels.Fields.Append fldParcel 'Add each field to the table
tblParcels.Fields.Append fldVFD
tblParcels.Fields.Append fldURN
tblParcels.Fields.Append fldSBI
tblParcels.Fields.Append fldTransSBI
tblParcels.Fields.Append fldLeaseEndDate
tblParcels.Fields.Append fldWorkCat
tblParcels.Fields.Append fldException
db.TableDefs.Append tblParcels 'Add the table to the database
db is the current database, and this code works fine, in that it creates a table called tblParcels with all the fields named above.
However, I'm trying to use what seems like exactly the same logic to create a different table in another sub, and the table isn't being created:
On Error Resume Next
DoCmd.RunSQL "DROP TABLE tblNonRLE" 'This deletes the table if it already exists.
Dim tblNonRLE As TableDef 'Create the table
Set tblNonRLE = db.CreateTableDef("tblNonRLE") 'Define the table
Dim fldID As Field
Dim fldTemplate As Field 'Create each of the fields
Dim fldURN As Field
Dim fldSBI As Field
Dim fldSheetRef As Field
Dim fldParcelRef As Field
Dim fldArea As Field
Set fldID = tblNonRLE.CreateField("ID", dbLong)
Set fldTemplate = tblNonRLE.CreateField("Template", dbText, 6)
Set fldURN = tblNonRLE.CreateField("URN", dbText, 10)
Set fldSBI = tblNonRLE.CreateField("SBI", dbText, 9)
Set fldSheetRef = tblNonRLE.CreateField("SheetRef", dbText, 6)
Set fldParcelRef = tblNonRLE.CreateField("ParcelRef", dbText, 4)
Set fldArea = tblNonRLE.CreateField("Template", dbText, 8)
tblNonRLE.Fields.Append fldID
tblNonRLE.Fields.Append fldTemplate
tblNonRLE.Fields.Append fldURN
tblNonRLE.Fields.Append fldSBI
tblNonRLE.Fields.Append fldSheetRef
tblNonRLE.Fields.Append fldParcelRef
tblNonRLE.Fields.Append fldArea
db.TableDefs.Append tblNonRLE 'Add the table to the database
I don't get an error message, but the table doesn't get created. This is my third post in the week since I started playing with VB - and I know I may be missing something silly, but you've been helpful so far so any thoughts would be welcome!
thanks