使用VBA变量查询记录集 [英] Querying a recordset with VBA Variables

查看:161
本文介绍了使用VBA变量查询记录集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的问题最初始于我想要将一个表单上输入的日期与另一个表单的子表单上输入的日期进行比较(我希望这不会太混乱)。通过大量的试验和错误,我发现不可能这样做,因为1)其他子表格必须打开2)搜索子表格的主要形式必须已经在正确的记录上(头痛!) 。


然后我偶然发现了记录集。我想我找到了解决方案。但是我有一些顾虑。

  • 我是否使用DAO记录集或ADO记录集(只是尝试访问表并将其值与某些VB变量进行比较)
  • 我的语法是否正确对于查询
  • 为什么它会以空记录集返回?

展开 | 选择 | 换行 | 行号

解决方案

你好Cintury,


这是一个Access数据库问题吗?如果是这样,它可能应该在Access论坛而不是VB6论坛(特别是因为Access使用的VBA和全口VB之间存在很多差异)


假设这个是访问:


根据您的情况实施可能更简单的一种解决方法是创建一个带有第二个日期字段的测试表单,打开为隐藏在Date控件的AfterUpdate事件中(组合/文本任意框)。打开隐藏表单的代码如下所示:

展开 | 选择 | Wrap | 行号


这是指向如何突出显示a的线程的链接使用recordset / .findfirst列表框中的特定记录


不完全是您正在寻找的内容,但可以帮助您更多地了解记录集...

http://www.thescripts.com/forum/thread689835.html


问候,

Scott


忽略我,我只是注册了对这个帖子的兴趣所以我会收到更新的通知。


Ok the problem originally started with me wanting to compare the dates entered on one form with the dates entered on a different form''s subform (I hope that wasn''t too confusing). Thru numerous trials and error, I discovered that it was not possible to do it this way since 1) the other subform had to be open and 2) the main form of the searchee subform had to be on the correct record already (headache!).

Then I stumbled onto recordsets. I think I''ve found the solution. However I have a few concerns.

  • Do I use a DAO recordset or an ADO recordset (just trying to access a table and compare its values to some VB variables)
  • Is my syntax correct for the query
  • Why is it coming back with an empty recordset?

Expand|Select|Wrap|Line Numbers

解决方案

Hi Cintury,

Is this an Access db problem? If so, it should probably be in the Access forum instead of the VB6 forum (especially since there are numerous differences between the VBA that Access uses and full-bore VB)

Assuming that this IS Access:

One work-around that is probably simpler to implement with your situation is to create a ''test form'' with your second date field in it, that you open as Hidden in the AfterUpdate event of your Date control (combo/text whatever box). The code for opening a hidden form looks like this:

Expand|Select|Wrap|Line Numbers


Here is a link to a thread discussing how to highlight a specific record in a listbox using recordset/.findfirst

Not exactly what you''re looking for, but may help you understand recordsets a bit more...

http://www.thescripts.com/forum/thread689835.html

Regards,
Scott


Ignore me, I''m just registering an interest in this thread so I''ll be notified of updates.


这篇关于使用VBA变量查询记录集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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