将全局变量传递给查询条件 [英] Passing global variable to query criteria

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

问题描述

我正在尝试使用以下代码将全局变量传递给查询中的条件,但查询没有返回任何结果。我在查询的条件中包含函数ReturnStrCriteria()。当我手动将标准放入查询(如* 2007)时,它返回结果。不知道我做错了什么。任何建议,将不胜感激。谢谢


I am trying to pass a global variable to criteria in a query using the below code, but the query is returning no results. I have the function ReturnStrCriteria() included in the query''s criteria. When I manually put the criteria into the query (Like "*2007"), it returns results. Not sure what I''m doing wrong. Any suggestions would be appreciated. Thanks



展开 | 选择 | Wrap | 行号

推荐答案

嗨。在您提供的按钮单击代码中,根本没有调用函数ReturnStrCriteria()。它目前不用于设置标准字符串。


我看不到它会去哪里,因为你现在有一个FOR循环从列表框的内容构建你的标准字符串。


无论如何,将局部变量设置为全局值的调用将采用 StrCriteria = ReturnStrCriteria()的形式但是没有你的代码中有这样的陈述。


-Stewart
Hi. In the button click code as you have provided it there is no call to the function ReturnStrCriteria() at all. It is not being used to set your criterion string at present.

I cannot see where it would go, as you have a FOR loop building your criterion string from the contents of a list box at present.

Anyway, a call which sets your local variable to the value of the global would be of the form StrCriteria=ReturnStrCriteria() but there isn''t a statement like this in your code.

-Stewart


也许可以尝试将其添加到以下行:


strCriteria = strCriteria& 喜欢''" &安培; Chr(34)_


我所做的只是在Like之后添加'',但每当我使用like函数返回结果时,这对我有用。
Maybe try adding this to the following line:

strCriteria = strCriteria & "Like ''" & Chr(34) _

All I did was add an '' after the Like, but whenever I use a like function to return results, that works for me.


我尝试添加单引号但没有运气。如果我尝试传递类似January_2007的内容,它可以正常工作。


当使用ReturnStrCriteria()作为标准手动运行查询时,我甚至无法使用以下工作。

I tried adding the single quote but no luck. It works fine if I try to pass something like "January_2007".

I can''t even get the below to work when just running the query manually using ReturnStrCriteria() as the criteria.

展开 | 选择 | < span class =codeLinkonclick =WordWrap(this);> Wrap | 行号


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

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