Boa tarde!
Estou tentando criar uma tabela pelo VBA já alterando algumas propriedades dos campos, mas aponta o erro "Operação Inválida" na linha marcada em vermelho. Estou tentando criar a tabela através de um procedimento em outro banco de dados que não tem nenhuma ligação com este.
Sub RecreateMicrobiologyTable()
Dim db As DATABASE
Dim tblDef As TableDef
Dim fld As Field
Set db = OpenDatabase("C:\teste.mdb")
Set tblDef = db.CreateTableDef("Microbiology")
Set fld = tblDef.CreateField("Micro_ID", dbLong)
fld.Attributes = dbAutoIncrField
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Date", dbDate)
fld.Properties.Append fld.CreateProperty("Format", dbText, "Short Date")
fld.DefaultValue = DateValue(Date)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Name", dbText, 50)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Breed", dbText, 10)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Age", dbLong)
' fld.FieldSize = "Integer"
' fld.DecimalPlaces = 0
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Lab", dbText, 100)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Collector", dbText, 60)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Time", dbDate)
fld.Properties.Append fld.CreateProperty("Format", dbText, "Short Time")
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Interval", dbByte)
' fld.DecimalPlaces = 0
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Type", dbNumeric)
fld.Properties.Append fld.CreateProperty("DisplayControl", dbText, "ComboBox")
fld.Properties.Append fld.CreateProperty("RowSourceType", dbText, "Table/Query")
fld.Properties.Append fld.CreateProperty("RowSource", dbText, "SELECT * FROM Microbiology_Sample_Types ORDER BY [Type_Name];")
fld.Properties.Append fld.CreateProperty("BoundColumn", dbInteger, 1)
fld.Properties.Append fld.CreateProperty("ColumnCount", dbInteger, 2)
fld.Properties.Append fld.CreateProperty("ColumnWidth", dbText, "0cm;2,54cm")
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Bacteria", dbNumeric)
fld.Properties.Append fld.CreateProperty("DisplayControl", dbText, "ComboBox")
fld.Properties.Append fld.CreateProperty("RowSourceType", dbText, "Table/Query")
fld.Properties.Append fld.CreateProperty("RowSource", dbText, "SELECT * FROM Microbiology_Bacteria ORDER BY [Bacteria_Name];")
fld.Properties.Append fld.CreateProperty("BoundColumn", dbInteger, 1)
fld.Properties.Append fld.CreateProperty("ColumnCount", dbInteger, 2)
fld.Properties.Append fld.CreateProperty("ColumnWidth", dbText, "0cm;2,54cm")
tblDef.Fields.Append fld
db.TableDefs.Append tblDef
MsgBox "Foi!"
End Sub
Alguém ajuda? Ainda estou boiando um pouco nesta questão de criar tabelas e campos... Se puderem também avaliar o procedimento inteiro, ficarei imensamente agradecido!
Estou tentando criar uma tabela pelo VBA já alterando algumas propriedades dos campos, mas aponta o erro "Operação Inválida" na linha marcada em vermelho. Estou tentando criar a tabela através de um procedimento em outro banco de dados que não tem nenhuma ligação com este.
Sub RecreateMicrobiologyTable()
Dim db As DATABASE
Dim tblDef As TableDef
Dim fld As Field
Set db = OpenDatabase("C:\teste.mdb")
Set tblDef = db.CreateTableDef("Microbiology")
Set fld = tblDef.CreateField("Micro_ID", dbLong)
fld.Attributes = dbAutoIncrField
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Date", dbDate)
fld.Properties.Append fld.CreateProperty("Format", dbText, "Short Date")
fld.DefaultValue = DateValue(Date)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Name", dbText, 50)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Breed", dbText, 10)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Age", dbLong)
' fld.FieldSize = "Integer"
' fld.DecimalPlaces = 0
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Lab", dbText, 100)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Collector", dbText, 60)
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Time", dbDate)
fld.Properties.Append fld.CreateProperty("Format", dbText, "Short Time")
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Tier_Interval", dbByte)
' fld.DecimalPlaces = 0
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Type", dbNumeric)
fld.Properties.Append fld.CreateProperty("DisplayControl", dbText, "ComboBox")
fld.Properties.Append fld.CreateProperty("RowSourceType", dbText, "Table/Query")
fld.Properties.Append fld.CreateProperty("RowSource", dbText, "SELECT * FROM Microbiology_Sample_Types ORDER BY [Type_Name];")
fld.Properties.Append fld.CreateProperty("BoundColumn", dbInteger, 1)
fld.Properties.Append fld.CreateProperty("ColumnCount", dbInteger, 2)
fld.Properties.Append fld.CreateProperty("ColumnWidth", dbText, "0cm;2,54cm")
tblDef.Fields.Append fld
Set fld = tblDef.CreateField("Micro_Sample_Bacteria", dbNumeric)
fld.Properties.Append fld.CreateProperty("DisplayControl", dbText, "ComboBox")
fld.Properties.Append fld.CreateProperty("RowSourceType", dbText, "Table/Query")
fld.Properties.Append fld.CreateProperty("RowSource", dbText, "SELECT * FROM Microbiology_Bacteria ORDER BY [Bacteria_Name];")
fld.Properties.Append fld.CreateProperty("BoundColumn", dbInteger, 1)
fld.Properties.Append fld.CreateProperty("ColumnCount", dbInteger, 2)
fld.Properties.Append fld.CreateProperty("ColumnWidth", dbText, "0cm;2,54cm")
tblDef.Fields.Append fld
db.TableDefs.Append tblDef
MsgBox "Foi!"
End Sub
Alguém ajuda? Ainda estou boiando um pouco nesta questão de criar tabelas e campos... Se puderem também avaliar o procedimento inteiro, ficarei imensamente agradecido!