我尝试创建一个指向Oracle的链接表。为简单起见,我从一个运行良好的手动创建的链表中“窃取”了连接字符串。代码在Append中断,如下所示。任何线索?谢谢!
Sub CreaOra()
Dim db As DAO.Database
Dim td As DAO.TableDef
Dim strConn As String
Set db = CurrentDb
'connection string copied from a working linked table !'
strConn = "ODBC;DRIVER={Oracle in OraClient10g_home1};SERVER=ORAJJJ0;UID=xxx;PWD=yyy;DBQ=ORAWOD0;"
Set td = db.CreateTableDef(Name:="test", SourceTableName:="ORAJJJC01.TBL_MYTBL", Connect:=strConn)
'next row -> error 3264 No field defined--cannot append TableDef or Index
db.TableDefs.Append td
Set td = Nothing
Set db = Nothing
End Sub
答案 0 :(得分:3)
attributes参数不能为空。您需要传递0或dbAttachSavePWD
Set td = db.CreateTableDef(Name:="test", Attributes:=0, SourceTableName:="ORAJJJC01.TBL_MYTBL", Connect:=strConn)
如果您不想将其明确设置为0
,则可以执行此操作 Set td = db.CreateTableDef("test")
td.SourceTableName:="ORAJJJC01.TBL_MYTBL"
td.Connect:=strConn
注意:如果您在监视窗口中查看td,则可以观察到,如果您没有为属性传递值,则Connect和SourceTableName将设置为空,但在您执行时仍然保留。