请各位老师指点,如何在已有ACCESS数库中,如何跟据已有的ACCESS数据表结构各字段属性,创建一份一样的空数据表 最好是通过窗体动态的创建,下面是我自己写的一段代码,但运行不成功 Private Sub CommandButton1_Click() '新建数据表 Dim cmd As New ADODB.Command Dim mytable As String Dim myoldtable As String mytoldable = ComboBox1 '已有数据表名称 mytable = TextBox1 '创建数据表名称 Call mydata '建立与数据连接 '判断新建数据表名是否已经存在 Set rst = CNN.OpenSchema(adSchemaTables) Do While Not rst.EOF If LCase(rst!TABLE_NAME) = LCase(mytable) Then MsgBox "数据表已存在!", vbCritical, "警告" Exit Sub End If rst.MoveNext Loop Set cmd.ActiveConnection = CNN sql = "select * into " & mytable & " from " & myoldtable & " where 1 <> 1" With cmd .CommandText = sql .Execute , , adCmdTextExecute End With CNN.Close Set rst = Nothing Set cmd = Nothing Set CNN = Nothing MsgBox "数据表<" & mytable & ">创建成功!", vbInformation, "创建数据表" End Sub |
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) | Powered by Discuz! X3.3 |