如何重置表单(绑定查询)

发布于 2024-12-08 12:19:11 字数 990 浏览 0 评论 0原文

在我的 Access 2010 数据库中,我有两个表:客户(包含列:client_id、名称)和订单(包含列:order_id、client_id、描述)。我有一个名为orders_with_clients的查询,它连接客户及其订单(类似于“selectorders.client_id,orders.description,clients.name fromorders joinclients onorders.client_id=clients.client_id”)。我可以插入到这个查询中。我可以通过两种方式插入它:

  1. 我可以提供 client_id 和描述(类似于“插入orders_with_clients(client_id,描述)值(3,'三双袜子')”) - 在这种情况下,Access 创建一个订单表中的新行(通过外键)与客户表中的现有行连接。

  2. 我可以提供名称和描述(类似于“插入orders_with_clients(名称,描述)值('Zenon','三双袜子')”) - 在这种情况下,Access 在客户表中创建一个新行,然后订单表中的一个新行(通过外键)与这个新客户端连接。

我有一个与查询orders_with_clients 绑定的表单。它有三个字段:client_id(可能是组合框或文本字段 - 我不在乎)、名称和描述(都是文本字段)。当然,在任何时候,用户仅使用其中两个字段:client_id 和描述或名称和描述。

client_id 字段由一些 VBA 代码根据其他形式中发生的情况进行控制(设置)。我的意思是,当发生某些事件时,我的 VBA 代码将 client_id 字段设置为某个值。我还希望有时 VBA 代码会将此表单重置为清除、空状态 - 包括设置 client_id 字段以清除新的空状态。这就是我遇到问题的地方。我尝试执行“fieldname.value=0”和“fieldname.value=null”,但 Access 表示此处放置 null 是错误的。我还尝试执行类似“formname.requery”的操作,但它导致当前状态被保存到数据库中。

我该怎么做?

In my Access 2010 database I have two tables: clients (with columns: client_id, name) and orders (with columns: order_id, client_id, description). I have a query called orders_with_clients which joins clients and their orders (something like "select orders.client_id, orders.description, clients.name from orders join clients on orders.client_id=clients.client_id"). I can insert into this query. I can insert into it in two ways:

  1. I can provide client_id and description (something like "insert into orders_with_clients (client_id, description) values (3, 'three pairs of socks')") - in such case Access creates a new row in orders table connected (by the foreign key) with existing row from clients table.

  2. I can provide name and description (something like "insert into orders_with_clients (name, description) values ('Zenon', 'three pairs of socks')") - in such case Access creates a new row in clients table and then a new row in orders table connected (by the foreign key) with this new client.

I have a form bound with query orders_with_clients. It has three fields: client_id (it may be a combobox or a textfield - I don't care), name and description (both textfields). Of course at any time user uses only two of those fields: client_id and description or name and description.

The field client_id is controlled (set) by some VBA code based on what happens in some other forms. I mean, when some events occur, my VBA code sets client_id field to some value. I also want that sometimes VBA code resets this form to clear, empty state - including setting client_id field to clear new empty state. And this is where I have problem. I tried to do "fieldname.value=0" and "fieldname.value=null", but Access says it is an error to put null here. I also tried to do something like "formname.requery", but it caused it current state to be saved to database.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵情客 2024-12-15 12:19:11

这是一个绑定表单,客户端 ID 希望绑定到关键字段,您不想更改它。

之后,这一切都取决于您想做什么。您想使用该表格来输入数据吗?在这种情况下,使用新参数打开表单。您想用不同的 ID 打开吗?然后重新打开表单或设置记录源。

This is a bound form and client id will, hopefully, be bound to a key field, you do not want to change it.

After that, it all depends on what you want to do. Do you wish to use the form for data entry? In which case open the form with new arguments. Do you wish to open with a different ID? Then reopen the form or set the recordsource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文