简体   繁体   English

MS Access VBA直通查询连接字符串错误(ODBC)

[英]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.

相关问题 带有“返回记录:否”的 MS Access Pass-Through 查询会截断 ODBC Connect Str - MS Access Pass-Through Query With "Returns Records: No" Truncates ODBC Connect Str MS Access SQL 直通查询 - MS Access SQL Pass Through Query 在 MS Access 中处理过滤的直通查询 - Dealing with filtered Pass Through Query in MS Access MS ACCESS-查询通过查询进行,并且VBA中存在错误。 如何修改查询? - MS ACCESS - the query works through a query, and there is an error in the VBA. How to modify the query? MS Access VBA:使用workspace.OpenDatabase通过ODBC连接连接到不可用的SQL Server-优雅的恢复? - MS Access VBA: Using workspace.OpenDatabase to connect to an unavailable SQL server via an ODBC connection - elegant recovery? 为什么 ms-access sql Pass Through 在 VBA 中不起作用 - Why does an ms-access sql Pass Through not work in VBA 通过dsn错误进行ODBC连接 - ODBC connection through dsn error MS-ACCESS通过“传递”删除ODBC链接表中的行 - MS-ACCESS Delete Rows in ODBC Linked Table via “Pass-Through” 如何通过 SQL Query 在 MS Access 中获取链接的 odbc 表的列 - How to get the columns of a linked odbc table in MS Access through SQL Query 使用用户输入作为过滤条件的传递查询 - MS Access - Pass-through query with user input as filter criteria - MS Access
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM