简体   繁体   English

编辑 Passthrough SQL 在 Microsoft Access 中使用替换查询 VBA

[英]Editing Passthrough SQL Query with Replace in Microsoft Access VBA

In Access I have a SQL passthrough query that returns an entire table filtered by first name.在 Access 中,我有一个 SQL 直通查询,它返回按名字过滤的整个表。

Example例子

SELECT * FROM dbo.Original_Data
WHERE first_name = 'Mike';

I am trying to write some VBA that on click of a button takes the passthrough query and replaces 'Mike' with any name I put in (this will later be done by a combo box but that's another step).我正在尝试编写一些 VBA,在单击按钮时会进行直通查询并用我输入的任何名称替换“Mike”(稍后将通过组合框完成,但这是另一个步骤)。

I have this where TempPT is the name of the passthrough query.我有这个,其中 TempPT 是直通查询的名称。

Private Sub Command12_Click()

TempPT = Replace(TempPT, "Mike", "Sam")    
DoCmd.OpenQuery "TempPT"

End Sub

This doesn't work.这行不通。

Is there a way that whatever I type in where I have 'Sam' is what the passthrough query will filter by?有没有一种方法可以让我在有“Sam”的地方输入的任何内容都是直通查询过滤的内容?

I am using passthrough because the DB is huge and clogs up Access.我正在使用直通,因为数据库很大并且阻塞了访问。

You need to edit the SQL property of the query.您需要编辑查询的SQL属性。 Probably something like this:大概是这样的:

With CurrentDb().QueryDefs("TempPT")
    .SQL = Replace(.SQL, "Mike", "Sam") 
End With

DoCmd.OpenQuery "TempPT"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM