传递全局变量进行查询 [英] passing a global variable to query

查看:85
本文介绍了传递全局变量进行查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我试图将全局变量中的值传递给查询。我知道这不能明确地完成,但我使用了一个名为get_global的小函数来返回变量的值。当我这样做时:


msgBox(get_global(&#KeyWordsSelected")


我收到一个消息框,其中包含我想要的值(我只是为了调试而做这个;它不是应用程序的关键元素。)在这个例子中,说它返回


''空气质量''


当我取这个值(在消息框中)并将其复制到我的查询中时,它可以很好地工作。例如:


WHERE( ((tblSubProjectKeyWords.ProjectKeyWords)=''空气质量''));


然而,当我使用


WHERE(((tblSubProjectKeyWords) .ProjectKeyWords)= get_glob al(" KeyWordsSelected")));


我什么都没回来。


我正在努力拼凑这个一起对SQL或Access知之甚少,所以我很感激任何建议。是否有一些我不遵循的语法规则?


谢谢!

Whitney

解决方案

最有可能是报价问题。它将被评估的是


WHERE(((tblSubProjectKeyWords.ProjectKeyWords)=空气质量));


你可能需要追加's。请尝试以下方法。我在双引号中附加单引号。


ProjectKeyWords)="''" &安培; get_global(" KeyWordsSelected")& "''"));


在评估SQL逻辑之前对函数进行求值,因此如果您逐步考虑它,您将了解SQL解析器要查看的内容。


除了全局变量,如果可能的话,你当然可以直接从表格中引用这个值。


ProjectKeyWords ="' " &安培;表格!MyForm!txtKeywords& "''"

其中txtKeywords是一个带有值的文本框。一切都取决于什么是最合适的。


你好,


我试图传递价值查询的全局变量。我知道这不能明确地完成,但我使用了一个名为get_global的小函数来返回变量的值。当我这样做时:


msgBox(get_global(&#KeyWordsSelected")


我收到一个消息框,其中包含我想要的值(我只是为了调试而做这个;它不是应用程序的关键元素。)在这个例子中,说它返回


''空气质量''


当我取这个值(在消息框中)并将其复制到我的查询中时,它可以很好地工作。例如:


WHERE( ((tblSubProjectKeyWords.ProjectKeyWords)=''空气质量''));


然而,当我使用


WHERE(((tblSubProjectKeyWords) .ProjectKeyWords)= get_glob al(" KeyWordsSelected")));


我什么都没回来。


我正在努力拼凑这个一起对SQL或Access知之甚少,所以我很感激任何建议。是否有一些我不遵循的语法规则?


谢谢!

惠特尼


感谢您的想法。不幸的是它没有用。我在变量本身附加单引号,所以字面上变量包含值


''空气质量''


单引号已经开启。他们会在解析过程中以某种方式被剥夺吗?


我也会考虑你的第二个建议,谢谢。


惠特尼


这很可能是报价问题。它将被评估的是


WHERE(((tblSubProjectKeyWords.ProjectKeyWords)=空气质量));


你可能需要追加's。请尝试以下方法。我在双引号中附加单引号。


ProjectKeyWords)="''" &安培; get_global(" KeyWordsSelected")& "''"));


在评估SQL逻辑之前对函数进行求值,因此如果您逐步考虑它,您将了解SQL解析器要查看的内容。


除了全局变量,如果可能的话,你当然可以直接从表格中引用这个值。


ProjectKeyWords ="' " &安培;表格!MyForm!txtKeywords& "''"

其中txtKeywords是一个带有值的文本框。一切都取决于最合适的。


尝试将此添加到查询的选择部分:

SELECT field1,field2等,get_global (" KeyWordsSelected")as tmpValue

FROM Table

WHERE tblSubProjectKeyWords.ProjectKeyWords = tmpValue;



你好,


我试图将全局变量中的值传递给查询。我知道这不能明确地完成,但我使用了一个名为get_global的小函数来返回变量的值。当我这样做时:


msgBox(get_global(&#KeyWordsSelected")


我收到一个消息框,其中包含我想要的值(我只是为了调试而做这个;它不是应用程序的关键元素。)在这个例子中,说它返回


''空气质量''


当我取这个值(在消息框中)并将其复制到我的查询中时,它可以很好地工作。例如:


WHERE( ((tblSubProjectKeyWords.ProjectKeyWords)=''空气质量''));


然而,当我使用


WHERE(((tblSubProjectKeyWords) .ProjectKeyWords)= get_glob al(" KeyWordsSelected")));


我什么都没回来。


我正在努力拼凑这个一起对SQL或Access知之甚少,所以我很感激任何建议。是否有一些我不遵循的语法规则?


谢谢!

惠特尼


Hello,

I am trying to pass the value in a global variable to a query. I know this can''t be done explicitly, but I''ve used a small function called get_global that returns the value of the variable. When I do this:

msgBox (get_global("KeyWordsSelected")

I get a message box with exactly the value I want (I am just doing this for debugging purposes; it is not a crucial element of the application). In this example, say it returns

''Air Quality''

When I take this value (that''s in the message box) and copy it into my query, it works perfectly. For example:

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=''Air Quality''));

However, when I use

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=get_glob al("KeyWordsSelected")));

I get nothing returned.

I am trying to cobble this together knowing little about SQL or Access, so I would appreciate any advice. Is there some syntax rule I am not following?

Thanks!
Whitney

解决方案

It is most likely the quote issue. What it would be getting evaluated to is

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=Air Quality));

you may need to append the ''s. Try the following. I am appending a single quote inside double quotes.

ProjectKeyWords)="''" & get_global("KeyWordsSelected") & "''"));

Functions are evaluated before the SQL logic is evaluated so if you think of it step by step, you will understand what the SQL parser wantes to see.

Along with globals, you can of course reference the value directly from a form if it is possible.

ProjectKeyWords="''" & Forms!MyForm!txtKeywords & "''"
where txtKeywords is a text box wih the value. all depends on what is most appropriate.

Hello,

I am trying to pass the value in a global variable to a query. I know this can''t be done explicitly, but I''ve used a small function called get_global that returns the value of the variable. When I do this:

msgBox (get_global("KeyWordsSelected")

I get a message box with exactly the value I want (I am just doing this for debugging purposes; it is not a crucial element of the application). In this example, say it returns

''Air Quality''

When I take this value (that''s in the message box) and copy it into my query, it works perfectly. For example:

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=''Air Quality''));

However, when I use

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=get_glob al("KeyWordsSelected")));

I get nothing returned.

I am trying to cobble this together knowing little about SQL or Access, so I would appreciate any advice. Is there some syntax rule I am not following?

Thanks!
Whitney


Thanks for the idea. Unfortunately it did not work. I do append the single quotes in the variable itself, so literally the variable contains the value

''Air Quality''

with the single quotes already on. Could they be stripped somehow in the parsing process?

I will look into your second suggestion too, thanks.

Whitney

It is most likely the quote issue. What it would be getting evaluated to is

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=Air Quality));

you may need to append the ''s. Try the following. I am appending a single quote inside double quotes.

ProjectKeyWords)="''" & get_global("KeyWordsSelected") & "''"));

Functions are evaluated before the SQL logic is evaluated so if you think of it step by step, you will understand what the SQL parser wantes to see.

Along with globals, you can of course reference the value directly from a form if it is possible.

ProjectKeyWords="''" & Forms!MyForm!txtKeywords & "''"
where txtKeywords is a text box wih the value. all depends on what is most appropriate.


Try adding this to the select part of your query:

SELECT field1, field2, etc, get_global("KeyWordsSelected") As tmpValue
FROM Table
WHERE tblSubProjectKeyWords.ProjectKeyWords=tmpValue;


Hello,

I am trying to pass the value in a global variable to a query. I know this can''t be done explicitly, but I''ve used a small function called get_global that returns the value of the variable. When I do this:

msgBox (get_global("KeyWordsSelected")

I get a message box with exactly the value I want (I am just doing this for debugging purposes; it is not a crucial element of the application). In this example, say it returns

''Air Quality''

When I take this value (that''s in the message box) and copy it into my query, it works perfectly. For example:

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=''Air Quality''));

However, when I use

WHERE (((tblSubProjectKeyWords.ProjectKeyWords)=get_glob al("KeyWordsSelected")));

I get nothing returned.

I am trying to cobble this together knowing little about SQL or Access, so I would appreciate any advice. Is there some syntax rule I am not following?

Thanks!
Whitney


这篇关于传递全局变量进行查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆