vba - 通过 VBA 访问添加到现有的直通查询
问题描述
我很好奇是否可以在不更改当前内置内容的情况下添加到现有的直通查询。
例子; 如果我有一个包含以下代码的直通查询:
SELECT MailYear, offer, CompanyCode, SeasonFlag, Season_Id, Description_Full, EarlyBirdDate, Description, Price_Type, Offer_Type, Page_Count, FirstReleaseMailed, InternetActiveDate
from CatCov
where offer = 'VG'and MailYear in ('2021', '2020')
我想在下一行添加一些东西。这是可能的吗?如果是这样,是否有人有任何 VBA 示例,他们应该向我展示或指出我的方向?
我在尝试
db.QueryDefs.Delete "qryMaster"
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
strSELECT = "select MailYear, offer, CompanyCode, SeasonFlag, Season_Id, Description_Full, EarlyBirdDate, Description, Price_Type, Offer_Type, Page_Count, FirstReleaseMailed, InternetActiveDate " _
& "from CatCov where offer = 'VG'and MailYear in ('2021', '2020') "
strSQL1 = strSELECT
Set qdfPassThrough = db.CreateQueryDef("qryMaster")
qdfPassThrough.Connect = "ODBC;DSN=SupplyChainMisc;Description=SupplyChainMisc;Trusted_Connection=Yes;DATABASE=SupplyChain_Misc;"
qdfPassThrough.ReturnsRecords = True
qdfPassThrough.SQL = strSQL
rs.MoveNext
Do Until rs.EOF = True
strUNION = " Union SELECT MailYear, offer, CompanyCode, SeasonFlag, Season_Id, Description_Full, EarlyBirdDate, Description, Price_Type, Offer_Type, Page_Count, FirstReleaseMailed, InternetActiveDate " _
& "from CatCov where offer = 'TK' "
strSQL2 = StrUnion
qdfPassThrough.SQL = strSQL
rs.MoveNext
Loop
Else
MsgBox "No records"
End If
但这行不通。由于我有一个循环运行它If Not (rs.EOF And rs.BOF) Then
说“对象变量或未设置块变量”时出错。这是因为我添加了 With 语句,否则没关系。
我正在尝试设置一个循环,该循环将不断添加到直通查询,同时不影响已经存在的内容。
任何帮助,将不胜感激。
解决方案
推荐阅读
- javascript - 无法在 keyup 事件上从 div contenteditable 获取更新的内容
- javascript - Slick SlideradaptiveHeight 使通过 asNavFor 连接的滑块不同步
- amazon-web-services - 无服务器环境中多租户 ID 的 AWS Cognito JWT 与 URL 路径参数
- sql - 根据多个条件链接表
- json - Elasticsearch 最大字节长度超出异常
- php - 迭代/以编程方式替换多维数组中的值(在 Codeigniter 或 PHP 中)
- git - Azure 应用服务部署失败:平台“java”版本“11.0.8”不受支持
- python - Pandas 从累积的网络数据中获取最后一小时的平均速度
- java - 更快地执行批量更新
- javascript - 如何在 React Router 5.2.0 中将 props/params/state 传递给带有 Link 的路由?