VB+ACCESS问题(DAO)
--------------------编程问答-------------------- 加上10分,50分好看些 --------------------编程问答-------------------- DB_TEXT ? DB_INTEGER ? --------------------编程问答-------------------- 试试:Dim myfield As DAO.Field, mytable As DAO.TableDef --------------------编程问答-------------------- 分开来,看哪步出错
Dim obj As Object
Set obj = mytable.CreateField("题号", dbText, 4)
Debug.Print obj Is Nothing
Set myfield = obj
如果是 CreateField 出错,可能 DAO 不对中文支持不好,换成全英文试试。 --------------------编程问答-------------------- 改为:Dim myfield As DAO.Field, mytable As DAO.TableDef 不出错,但是没有新建表,怎么回事呀,求帮助 --------------------编程问答-------------------- 试试在结束前加上
mydb.Close
将游标数据写入磁盘文件。 --------------------编程问答--------------------
'下面代码我运行没有问题,你看一看--------------------编程问答-------------------- 7楼和楼主将各自的 Access 版本说明一下,看是否版本不同。
Private mydb As DAO.Database
Private myrecord As DAO.Recordset
Private nworkspace As DAO.Workspace
Private Sub Command1_Click()
Dim myfield As Field, mytable As TableDef
Set nworkspace = CreateWorkspace("nworkspace", "admin", "", dbUseJet)
Set mydb = nworkspace.OpenDatabase("d:\1.MDB", , ";")
Set mytable = mydb.CreateTableDef(Text2.Text & "试题")
Set myfield = mytable.CreateField("题号", dbText, 4)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("题型", dbText, 10)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("题目", dbText, 200)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("分值", dbInteger)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("难度", dbText, 4)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("知识点", dbText, 50)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("所在章节", dbText, 10)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("答案", dbText, 100)
mytable.Fields.Append myfield
Set myfield = mytable.CreateField("状态", dbInteger)
mytable.Fields.Append myfield
mydb.TableDefs.Append mytable
mydb.Close
nworkspace.Close
End Sub
补充:VB , 数据库(包含打印,安装,报表)