ms-access:如何进行正确的重新查询? [英] ms-access: how to do a proper requery?

查看:104
本文介绍了ms-access:如何进行正确的重新查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在分发ms-access-2007前端.后端是sql server.用户将单击一个按钮,它将从sql server 2008数据库返回查询.

i am distributing ms-access-2007 front ends. the back end is sql server. a user will click on a button and it will return a query from the sql server 2008 database.

如果用户再次单击该按钮,是否可以重新查询该查询?

is it possible to requery this query if the user clicks the button again?

通常,访问的行为是,如果再次查询它,它将显示旧结果.我如何使其刷新结果?

usually the behavior of access is that if you query it again, it displays old results. how do i make it refresh results?

推荐答案

如果您知道查询仍然是ActiveDatasheet,请重新查询:

If you know the query is still the ActiveDatasheet, requery that:

  Screen.ActiveDatasheet.Requery

如果您不知道(可以检查Screen.ActiveDatasheet.Name),则可以再次打开它(如果查询已经打开,它可能会也可能不会重新查询-我希望不会,但是我可能是错误的),那么它将是ActiveDatasheet,您可以重新查询.

If you don't know that (you could check Screen.ActiveDatasheet.Name), you can open it again (which may or may not requery if the query is already open -- I would expect it not to, but I could be wrong), and then it will be the ActiveDatasheet and you can requery that.

或者,您可以这样做:

  DoCmd.SelectObject acQuery, "NameOfYourQuery"
  Screen.ActiveDatasheet.Requery

这些方法中的一种或多种肯定会起作用.

Surely one or more of these methods will work.

但是让我指出,将表和查询用作用户界面对象不是一个好主意.相反,您应该制作允许用户与其中显示的数据进行交互的表单,因为这样可以使您对它们有更多的控制权.

But let me point out that it's not a good idea to use tables and queries as user interface objects. You should instead make forms for allow users to interact with the data displayed in them because that gives you far more control over them.

(很多人不知道的是数据表是一个表单对象,因此Screen.ActiveDatasheet的属性和方法与任何形式的属性和方法相同,这意味着您实际上可以将值分配给事件上的事件. Screen.ActiveDatasheet对象并触发它们;但是我不建议您将其作为构建UI的最简单方法...)

(one thing that many people do not know is that a datasheet is a form object, so the properties and methods of Screen.ActiveDatasheet are the same as those of any form, which means you can actually assign values to events on the Screen.ActiveDatasheet object and have them fire; but I wouldn't recommend this as the easiest route to building a UI...)

这篇关于ms-access:如何进行正确的重新查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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