3

如何使用 vba 在Access 2007. Sql我使用以下代码制作表格vba

DoCmd.RunSQL "SELECT * INTO table2 FROM table1", True    
RefreshDatabaseWindow
DoCmd.TransferDatabase acExport, "Microsoft Access", "C:\import.mdb", , "table2", tab2, 0

RefreshDatabaseWindow错误消息:如果手动暂停和刷新,Microsoft Office Access 找不到对象 table2F5并运行返回以正常工作。如何自动完成?如果表列表处于活动状态,则在 Access 2003 中可以正常工作。

我尝试暂停但不工作:

Private Declare Sub sApiSleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
...
RefreshDatabaseWindow
Call sApiSleep(4000)
...
4

3 回答 3

1

这就是我用来附加 SQL/服务器表的方法。我删除它们,然后用此代码重新链接它们。显然,您必须为每个表重复最后一部分。我不知道这是否适用于 ADP。我的环境不使用 ADP。

Dim vConnect As String
Dim td As New TableDef
Dim vtablename As String

vConnect = "ODBC;Driver={SQL Server Native Client 10.0};SERVER=<server>;DATABASE=" <database>; Uid=<user>; Pwd=<pwd>;TrustServerCertificate=yes;encrypt = yes;"

'Delete existing tables
For Each td In CurrentDb.TableDefs
     vattributes = td.Attributes And dbAttachedODBC
     If Left(td.Name, 4) <> "Msys" And vattributes > 0 Then CurrentDb.TableDefs.Delete td.Name
Next
Debug.Print "Old Tables Deleted"

Set td = CurrentDb.CreateTableDef("<your table name>")
td.Connect = vConnect
td.SourceTableName = "<your table name>"
vtablename = td.Name
CurrentDb.TableDefs.Append td
Debug.Print "Attached table: " & vtablename
于 2012-11-26T07:31:48.223 回答
0

工作于Access 2007, 2010(项目.ADP):

RefreshDatabaseWindow
DoCmd.SelectObject acTable, "table2", True
DoCmd.TransferDatabase ...
于 2013-01-02T10:55:21.503 回答
0

这在 Access2010 中工作正常

在建表和 TransferDataBase 之间调用这个函数

函数 refrescarconexionBBDD()

Dim cadenaConexion As String

cadenaConexion = Application.CurrentProject.BaseConnectionString
Application.CurrentProject.CloseConnection

Application.CurrentProject.OpenConnection cadenaConexion

结束功能

于 2014-02-28T18:12:04.223 回答