Well I thought I had it figured out, the code does create the DB and it creates the first table, however when I try to creat a second table within the same DB I ger an error - 3240 (DB Exist) and it does not create the second table.
Below is the code I am using - (there are several more fields in each table) Can someone pleasepoint out my error?
Many Thanks
Sub Create_DB()
On Error GoTo Err
sDataBaseName = App.Path & "\Printing.mdb"
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsPrint = wrkDefault.CreateDatabase(sDataBaseName, _
dbLangGeneral, dbEncrypt) 'Create New Database
Set tdfWOPrint = dbsPrint.CreateTableDef("PrintWO"
'Create Table
Set tdfPSPrint = dbsPrint.CreateTableDef("PrintPS"
With tdfWOPrint
.Fields.Append .CreateField("Date", dbText, 12)
.Fields.Append .CreateField("PONum", dbText, 10)
.Fields.Append .CreateField("TOTAL", dbText, 50)
.Fields.Append .CreateField("LotNo", dbText, 15)
.Fields.Append .CreateField("ToDaysDate", dbText, 10)
End With
With tdfPSPrint
.Fields.Append .CreateField("PONum", dbText, 10)
.Fields.Append .CreateField("WONum", dbText, 10)
.Fields.Append .CreateField("DUEDATE", dbText, 12)
.Fields.Append .CreateField("CustomerName", dbText, 50)
.Fields.Append .CreateField("TEL", dbText, 36)
End With
dbsPrint.TableDefs.Append tdfWOPrint
dbsPrint.TableDefs.Append tdfPSPrint
dbsPrint.Close
Exit Sub
Err:
If Err.Number = 3204 Then 'DB Exists
Kill sDataBaseName
Resume
End If
End Sub
"The beauty of the second amendment is, that it will not be needed until
they try to take it." - Thomas Jefferson
Below is the code I am using - (there are several more fields in each table) Can someone pleasepoint out my error?
Many Thanks
Sub Create_DB()
On Error GoTo Err
sDataBaseName = App.Path & "\Printing.mdb"
Set wrkDefault = DBEngine.Workspaces(0)
Set dbsPrint = wrkDefault.CreateDatabase(sDataBaseName, _
dbLangGeneral, dbEncrypt) 'Create New Database
Set tdfWOPrint = dbsPrint.CreateTableDef("PrintWO"
Set tdfPSPrint = dbsPrint.CreateTableDef("PrintPS"
With tdfWOPrint
.Fields.Append .CreateField("Date", dbText, 12)
.Fields.Append .CreateField("PONum", dbText, 10)
.Fields.Append .CreateField("TOTAL", dbText, 50)
.Fields.Append .CreateField("LotNo", dbText, 15)
.Fields.Append .CreateField("ToDaysDate", dbText, 10)
End With
With tdfPSPrint
.Fields.Append .CreateField("PONum", dbText, 10)
.Fields.Append .CreateField("WONum", dbText, 10)
.Fields.Append .CreateField("DUEDATE", dbText, 12)
.Fields.Append .CreateField("CustomerName", dbText, 50)
.Fields.Append .CreateField("TEL", dbText, 36)
End With
dbsPrint.TableDefs.Append tdfWOPrint
dbsPrint.TableDefs.Append tdfPSPrint
dbsPrint.Close
Exit Sub
Err:
If Err.Number = 3204 Then 'DB Exists
Kill sDataBaseName
Resume
End If
End Sub
"The beauty of the second amendment is, that it will not be needed until
they try to take it." - Thomas Jefferson