Office中国论坛/Access中国论坛

标题: 如何用VB更改表名? [打印本页]

作者: ZZBZZBZZZB    时间: 2009-6-15 21:59
标题: 如何用VB更改表名?
Dim cnnmx As ADODB.Connection
Dim rsmx As ADODB.Recordset
Dim mxkm(500) As String, i As Integer, mysql As String, aq As String
    Set rsmx = New ADODB.Recordset
    mysql = "select  科目编码,总帐科目, 明细科目 into  aq   from 明细科目表  where  总帐科目 ='" & Combo12.Value & "'"
    rsmx.Open mysql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    CurrentDb.Execute "ALTER TABLE 'aq' RENAME '" & Combo12.Value & "'"
End Sub
提示这个有语法错误:CurrentDb.Execute "ALTER TABLE 'aq' RENAME '" & Combo12.Value & "'"
大哥,应如何做??请大哥帮助???多谢!!!
作者: benhh    时间: 2009-6-16 08:06
Try to use Me.Combo12 instead of Combo12.Value
作者: ZZBZZBZZZB    时间: 2009-6-16 17:41
问题解决!!代码如下:
Dim cnnmx As ADODB.Connection
Dim rsmx As ADODB.Recordset
Dim mxkm(500) As String, i As Integer, mysql As String, aq As String
Dim tyu产 As String
tyu产 = Combo12.Value
    Set rsmx = New ADODB.Recordset
    mysql = "select  科目编码 into  aq   from 总帐科目表  where  总帐科目 ='" & Combo12.Value & "'"
    rsmx.Open mysql, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
'更改表名"aq"为组合框的值"tyu产"
   DoCmd.Rename tyu产, acTable, "aq"
     '以下略




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3