如何保持组合框值不被更改回以前的值? [英] How do I keep a combo box value from being changed back to previous value?

查看:49
本文介绍了如何保持组合框值不被更改回以前的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,可以跟踪我的工作状态。不同的选择是:


1.新增

2.正在进行中

3.已完成

创建作业时,默认值为新建。我想要的是,一旦状态更改为正在进行或已完成,就会删除将状态更改回新状态的功能。我已经知道我需要在组合框的Before_Update事件中做到这一点,但是我不知道如何测试旧值以查看它是否大于1(意思是它的状态为正在进行或已完成,如果新值为1(新),在这种情况下,我将取消更新,并显示一条消息,说明为何状态无法更改为新。


部分问题是我不确定Me.JobStatus(组合框的名称)在Before_Update事件中的价值。例如,如果状态为2 - In Progress并且用户尝试将其更改为3 - Completed,则更新前Me.JobStatus的值是多少; 2或3?我希望这是有道理的。

I have a combo box that keeps track of the status of my jobs. The different options are:

1. New
2. In Progress
3. Completed

When I create a job, the default value is New. What I''m wanting is make it so that once the status has been changed to In Progress or Completed, the ability to change the status back to new is removed. I''ve gotten as far as to figure out that I need to do this in the Before_Update event of the combo box, but I can''t figure out how to test the old value to see if it was greater than 1 (meaning it had a status of either In Progress or Completed) and if the new value is 1 (New) in which case I would cancel the update with a message explaining why the status couldn''t be changed to New.

Part of my problem is that I''m not sure what the value of Me.JobStatus (the name of the combo box) is in the Before_Update event. For example, if the status is 2 - In Progress and the user attempts to change it to 3 - Completed, what is the value of Me.JobStatus before the update; 2 or 3? I hope that makes sense.

推荐答案

实际上,组合框(和文本框)有一个名为的属性.OldValue


我记得.Oldvalue包含加载记录时字段的值,并保留该值直到保存记录,或加载新记录。


我认为这应该可以满足您的需求。


这样的东西应该可以工作(未经测试的空气代码):
Actually the combobox (and textbox) has a property called .OldValue

As I recall the .Oldvalue contains the value of the field when the record was loaded, and retains the value until record is saved, or a new record is loaded.

I think that should satisfy your needs just fine.

Something like this should work (untested aircode):
展开 | 选择 | Wrap | 行号


或者,在控件源SQL中设置WHERE子句,使列表中只包含大于当前值的值。这样只有有效的选择才可用。
Alternatively, set a WHERE clause in your Control Source SQL such that only values greater than the current value are included in the list. That way only valid selections are even available.


@NeoPa,我刚试过你的建议,但问题是当你刚刚查看这份工作时,它会让组合框变成空白。 />

@TheSmileyCoder,由于某种原因,该值不会改变回先前的值。这使我无法移动到另一条记录。我认为Cancel = True部分会将值更改回先前的值。我尝试将值更改回.OldValue,但是我收到了错误。这就是我所拥有的:

@NeoPa, I just tried your suggestion, but the problem is that it make the combo box blank when you are just viewing the job.

@TheSmileyCoder, For some reason the value isn''t changing back to the previous value. This keeps me from being able to move to another record. I thought that the Cancel = True part would change the value back to the previous value. I tried changing the value back to be the .OldValue, but I got an error. Here is what I''ve got:

展开 | 选择 | Wrap | 行号


这篇关于如何保持组合框值不被更改回以前的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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