如何重置表单(绑定查询)
在我的 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”)。我可以插入到这个查询中。我可以通过两种方式插入它:
我可以提供 client_id 和描述(类似于“插入orders_with_clients(client_id,描述)值(3,'三双袜子')”) - 在这种情况下,Access 创建一个订单表中的新行(通过外键)与客户表中的现有行连接。
我可以提供名称和描述(类似于“插入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:
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个绑定表单,客户端 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.