在VB中如何修改access数据库的表名?
发布网友
发布时间:2022-04-24 08:49
我来回答
共3个回答
懂视网
时间:2022-05-03 07:44
VBA修改ACCESS表名
Private Sub changetabname_Click()
Dim tbl As TableDef
Dim dbs As Database
Dim nbl As String
Dim obl As String
nbl = "Newtable"
Set dbs = CurrentDb
For Each tbl In dbs.TableDefs
obl = tbl.Name
If obl = "Table1" Then
tbl.Name = nbl
MsgBox "修改成功", vbInformation, "提示"
End If
Next
End Sub
VBA修改ACCESS表名
标签:base sub inf tab ati led highlight mat 表名
热心网友
时间:2022-05-03 04:52
'修改表名要引用.Microsoft ADO Ext. 2.X for DDL and Security
Private Sub Command1_Click()
Dim db As New ADODB.Connection
db.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & "data source=" & App.Path & "\database.mdb"
db.Open
RenameTableName db, "oldTableName", "newTableName"
End Sub
'RenameTableName的返回值-1表示出错.
' 0表示没有存在要修改的表.
'1 表示成功
Public Function RenameTableName(DatabseConnectionObject As ADODB.Connection, strOldName As String, strNewName As String) As Integer
On Error GoTo acd
Dim tbl As ADOX.Table, cat As New ADOX.Catalog
Set cat.ActiveConnection = DatabseConnectionObject '设置目录的链接
RenameTableName = 0
For Each tbl In cat.Tables
If LCase(tbl.Name) = LCase(strOldName) Then
tbl.Name = strNewName '重命名表的名称
RenameTableName = 1
End If
Next
Exit Function
acd:
RenameTableName = -1
End Function
参考资料:http://topic.csdn.net/t/20060109/12/4505648.html
热心网友
时间:2022-05-03 06:10
用alert关键字