Set tbfTableDef = dbsDB.CreateTableDef(stgTblCasioContentTmp)
Set fldField = tbfTableDef.CreateField("Barcode", dbDouble)
tbfTableDef.Fields.Append fldField
Set fldField = tbfTableDef.CreateField("CurrentSP", dbDouble)
tbfTableDef.Fields.Append fldField
Set rst = dbsDB.OpenRecordset("TempCasioInput")
With rst
' Add new record to end of Recordset object.
.AddNew
!Barcode = Barcode
!CurrentSP = CurrentSP
End With
上面的都没问题,也能建立新表,但是但我打开数据集,准备添加数据时出问题。
如果前面定义 Dim rst as RecordSet,在后面写
Set rst = db.openrecordset("tblContact")
with rst
.addnew
时,在“Set rst....."又出现Error 13 类型不匹配,如果是定义Dim rst as RecordSets,
Error 13没有了,但是在".addnew"处又有"编译错误,method or data member not found?"
建立新表的DAO简例如下:你可参照一下(因你抄来的代码编的不是很顺畅)
Ps.建表用SQL更方便,也更快
Dim db As DAO.Database
Dim tbl As DAO.TableDef
Set db = CurrentDb
Set tbl = db.CreateTableDef("tblContact")
With tbl
.Fields.Append .CreateField("FirstName", dbText)
.Fields.Append .CreateField("LastName", dbText)
.Fields.Append .CreateField("hone", dbText)
.Fields.Append .CreateField("Notes", dbMemo)
End With
db.TableDefs.Append tbl