[英]MS Access VBA Pass Through Query Connection String Error (ODBC)
I am currently trying to write a pass through query using VBA that connects to an oracle database. 我目前正在尝试使用连接到oracle数据库的VBA编写传递查询。 Using the answer provided from SQL Server Passthrough query as basis for a DAO recordset in Access as a starting poing, I have the following VBA code.
使用SQL Server Passthrough查询提供的答案作为Access中DAO记录集的基础作为开始的步骤,我有以下VBA代码。
Option Compare Database
Sub Test_PassThroughQuery()
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Set qdf = CurrentDb.CreateQueryDef("")
qdf.Connect = "ODBC;DSN=database_name;UID=username;PWD=password;DBQ=ADPR;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;MLD=0;ODA=F;"
qdf.SQL = "SELECT * FROM DATE_TABLE"
qdf.ReturnsRecords = True
Set rst = qdf.OpenRecordset
Debug.Print rst
rst.Close
Set rst = Nothing
Set qdf = Nothing
End Sub
However, this prompts an error Type mismatch
on the Debug.Print rst
. 但是,这在
Debug.Print rst
上提示错误Type mismatch
。
For the connection string I am using the ODBC connection string from the Property tab. 对于连接字符串,我正在使用“属性”选项卡中的ODBC连接字符串。
EDIT Am I calling the Debug.print rst
line incorrectly? 编辑我是否在不正确地调用
Debug.print rst
行?
There are many ways to create pass-through queries. 有许多方法可以创建传递查询。 If you want to save a pass-through query in Access, you can set the first parameter of
CreateQueryDef
: 如果要在Access中保存传递查询,则可以设置
CreateQueryDef
的第一个参数:
Sub Test_PassThroughQuery()
Dim qdf As DAO.QueryDef, rst As DAO.Recordset
Set qdf = CurrentDb.CreateQueryDef("MyPassthroughQuery")
qdf.Connect = "ODBC;DSN=database_name;UID=username;PWD=password;DBQ=ADPR;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;MLD=0;ODA=F;"
qdf.SQL = "SELECT * FROM DATE_TABLE"
qdf.ReturnsRecords = True
DoCmd.OpenQuery "MyPassthroughQuery"
End Sub
This creates a saved query, and opens it. 这将创建一个保存的查询,并打开它。
You could also query an external data source in Access, which allows you to use the query designer, and use local tables and external data in a single query: 您还可以在Access中查询外部数据源,这使您可以使用查询设计器,并在单个查询中使用本地表和外部数据:
SELECT *
FROM [ODBC;DSN=database_name;UID=username;PWD=password;DBQ=ADPR;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;BTD=F;BNF=F;BAM=IfAllSuccessful;NUM=NLS;DPM=F;MTS=T;MDI=F;CSR=F;FWC=F;FBS=64000;TLO=O;MLD=0;ODA=F;].DATE_TABLE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.