如何访问MS Access程序中的查询 [英] How to access a query inside MS Access program

查看:76
本文介绍了如何访问MS Access程序中的查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨eveyone,


我第一次使用MS Access 2003,我需要修改现有程序


我有一个MS Access查询,我想逐个获取记录,并将结果写入文本文件。我可以使用MS Access OpenRecordSet()吗?如果是的话,

有人可以帮我解释语法吗?我尝试了以下代码,但它没有工作

Hi eveyone,

Its my first time to use MS Access 2003 and I need to modify the existing program

I have a MS Access query and I want to fetch the record 1 by 1 and write the result in a text file. Can I use MS Access OpenRecordSet() for this? If yes,
can anybody help me with the syntax? I tried the following code but it didn''t work

展开 | 选择 | Wrap | 行号

推荐答案

关于问题#1:

看来这个失败的原因是你引用的查询需要参数而你没有给它任何所以它失败了。对记录集数据源使用参数化查询并不简单,因此我将在此引用您:
http://support.microsoft.com/default...b;en-us;209203

除此之外应该打开你的记录集。另一个注意事项是在记录集的变量声明中,完全限定它总是一个好主意
Regarding issue #1:
It appears that the reason this is failing is that the query you are referencing expects parameters and you aren''t giving it any so it fails. It is not straightforward to use parameterized queries for your recordset datasource so I will reference you here:
http://support.microsoft.com/default...b;en-us;209203
Other than that it should open your recordset. One other note is in your variable declaration of the recordset it is always a good idea to fully qualify it as
展开 | 选择 | Wrap | 行号


您好janders468,


感谢您的回复,我确实尝试了DAO的声明,但我仍然得到了同样的错误信息。


For问题#1,对不起我没有提到我的查询调用是在一个Sub(程序)中从一个成功提供这些参数的表格中。


其实我试过用DoCmd.OpenQuery只是为了检查我的查询是否有效&没有错误,那就是。我用结果集执行了查询,但是我想将这些查询结果的每一列都分配给一个变量。我想我需要使用OpenRecordSet()方法,但问题是我不知道语法。


是否可以在OpenRecordset()方法中使用查询将结果提取到变量中?你能给我一些语法或者一些例子。



再次感谢....

EVH316



Hi janders468,

Thanks for the reply, I did try the declaration with DAO but still I end up with the same error message.

For issue #1, sorry I didn''t mentioned that the calling of my query is inside one of the Sub (procedure) from a form where these parameters are supplied successfully.

Actually I tried using DoCmd.OpenQuery just to check if my query is valid & error free, then it is. I got the query executed with the result set, but I want to assign each of the columns of these query results to a variable. I guess I need to use OpenRecordSet() method for this, but the thing is I don''t know the syntax.

Is it possible to use a query inside OpenRecordset() method to extract the result into a variable? Can you give me the syntax or maybe example.


Thanks Again....
EVH316




关于问题#1:

看来这个失败的原因是你引用的查询需要参数和你没有给它任何所以它失败了。对记录集数据源使用参数化查询并不简单,因此我将在此引用您:
http://support.microsoft.com/default...b;en-us;209203

除此之外应该打开你的记录集。另一个注意事项是在记录集的变量声明中,完全限定它总是一个好主意
Regarding issue #1:
It appears that the reason this is failing is that the query you are referencing expects parameters and you aren''t giving it any so it fails. It is not straightforward to use parameterized queries for your recordset datasource so I will reference you here:
http://support.microsoft.com/default...b;en-us;209203
Other than that it should open your recordset. One other note is in your variable declaration of the recordset it is always a good idea to fully qualify it as
展开 | 选择 | Wrap | 行号


您好EVH316,


我假设您拥有一个包含值的表单中的控件,并且该控件正在被提供给查询。虽然看起来这应该有资格作为填充参数但它没有,你会得到同样的错误。这是一个如何在代码中提供参数的快速而肮脏的示例。我不是真的这样做过,所以如果有更好的方法,任何人都可以随意纠正我,但这实际上是微软所说的。假设您有一个名为[Test]的参数。要实现的关键是你设置这个参数,然后使用QueryDef打开记录集。
Hi EVH316,

I am assuming that you have a control in a form that contains the value and that is being fed to the query. Even though it seems like this should qualify as filling the parameter it does not, and you will get this same error. Here is a quick and dirty example of how to supply the parameter within code. I don''t really ever do it this way so if there is a better way anyone can feel free to correct me, but this was essentially how Microsoft said to do it. This assumes you have a parameter called [Test]. The key point to realize is that you set this parameter and then use the QueryDef to open the recordset.
展开 | 选择 | Wrap | 行号


这篇关于如何访问MS Access程序中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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