简体   繁体   English

如何在表单中使用访问传递查询

[英]How to use access pass-through query in a form

I'm using pass-through query code below on access. 我在访问时使用下面的传递查询代码。 The code isn't a problem. 代码不是问题。 My problem is to make a form on access that enters the varible on the place indicated and returns me the table from que SQL select. 我的问题是要在访问时形成一个表格,在指定的位置输入变量,然后从que SQL select中返回表。 The regular solution: [Form]![Variable] doesn't work, because pass-through query doesn't support it I imagine (I'm not an Access expert). 常规解决方案:[Form]![Variable]不起作用,因为我想直通查询不支持它(我不是Access专家)。 Does anyone have a solution for this problem? 有人对此问题有解决方案吗?

SELECT instalacao
    ,tipounidade
FROM sgdprd.useccionadora us
INNER JOIN (
    SELECT bloco
    FROM sgdprd.redeprimaria rp
    WHERE rp.useccionadora IS NOT NULL CONNECT BY rp.nox = PRIOR rp.fontex
        AND rp.noy = PRIOR rp.fontey START
    WITH rp.utransformadora = (
            SELECT utransformadora
            FROM sgdprd.redeprimaria rp
            INNER JOIN sgdprd.consumidor con ON rp.utransformadora = con.instalacao
            WHERE con.conta = '**VARIABLE GOES HERE**'
            )
    ) lista ON lista.bloco = us.instalacao
WHERE us.tipounidade = 'DJ'
    OR us.tipounidade = 'RL'

You don't mention what you want to do with the results of this query? 您没有提及要对该查询的结果做什么?

Any pass-through query is read only. 任何传递查询都是只读的。

However, you can use the following code: 但是,您可以使用以下代码:

Dim strSQL As String

strSQL = "your sql goes here where con.contra='[P1]' bla bla"

strSQL = Replace(strSQL, "[P1]", Me.SomeControl)

With CurrentDb.QueryDefs("QryPass")
   .SQL = strSQL
End With

It is assumed that me.SomeControl in the form is say restricted to a number column since if it is a free form text box, then you are open to sql injection. 假定表单中的me.SomeControl被限制为一个数字列,因为如果它是自由格式的文本框,则您可以进行sql注入。 QryPass is simply a saved pass-though query and you can re-use that query over and over in code for any T-sql or server side commands you wish. QryPass只是一个保存的传递查询,您可以在代码中一遍又一遍地重复使用该查询,以获取所需的任何T-sql或服务器端命令。

As noted, you have to share additional information as to what you want to do with the pass-through query (such as assign to a recordset, combo box, report or even perhaps the forms recordsource - so addtitional info is needed to complete this problem, but the above provides a working example. 如前所述,您必须共享有关传递查询要执行的操作的其他信息(例如,分配给记录集,组合框,报表甚至表单记录源),因此需要其他信息才能解决此问题,但以上提供了一个有效的示例。

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

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