如何强制访问组合框的更新? [英] How to force the update of an Access combobox?

查看:372
本文介绍了如何强制访问组合框的更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种技术,我编码自己的状态时,可俯瞰?

Is there a technique I'm overlooking when coding my form?

我有一对层叠的连击。

  1. ComboSource筛选可供选择的ComboInformation

  1. ComboSource filters the options available for choice in ComboInformation

ComboInformation设置表中的一个必填字段的内容

ComboInformation sets the contents of a mandatory field in a table

行来源为ComboSource是:

The rowsource for ComboSource is:

SELECT tblSource.SourceID, tblSource.Source
FROM tblSource
ORDER BY tblSource.Source;

行来源为ComboInformation是:

The rowsource for ComboInformation is:

SELECT tblInformation.InformationID, tblInformation.SourceID, tblInformation.InformationSelector
FROM tblInformation
WHERE (((tblInformation.SourceID)=[ComboSource])) OR ((([ComboSource]) Is Null))
ORDER BY tblInformation.InformationSelector;

有有效来选择ComboSource一个值这导致.Listcount为ComboInformation为零。用户可以选择输入ComboInformation一个新的价值,并提示在链接到源表中的ComboSource项信息表创建相关的项目,或者他们可以选择导航回到ComboSource选择不同的来源。

It is valid to select a value in ComboSource which results in the .Listcount for ComboInformation being zero. The user can choose to type a new value in ComboInformation and be prompted to create the relevant item in the Information table linked to the ComboSource entry in the Source table, or they can choose to navigate back to ComboSource to select a different Source.

当用户编辑中的现有记录和改变ComboSource到一个值,使得不存在关联的信息记录的问题出现了。在After_Update事件ComboSource我有以下的code,旨在更新ComboInformation以反映新的来源,强制用户选择ComboInformation(否则他们可以保存信息的旧值的记录而没有意识到一个新的价值它)。

The problem arises when a user edits an existing record and changes ComboSource to a value for which there is no associated Information records. In the After_Update event for ComboSource I have the following code, intended to update ComboInformation to reflect the new source and force the user to select a new value for ComboInformation (otherwise they could save the record with the old value of Information without realising it).

Me.ComboInformation.Requery 'Reflect the current source

'Set a default value for ComboInformation
If Me.ComboInformation.ListCount > 0 Then
     Me.ComboInformation.DefaultValue = Me.InformationTitle.ItemData(0)
Else
     On Error Resume Next 'Ignore inevitable error
     Me.ComboInformation.DefaultValue = Null
     On Error GoTo PROC_ERR 'restore normal error handling
End If

'Force the user to update Information by setting content to "" -- if this isn't done, the
'record can be saved with the 'previous value of Information and the user may not realise 
'they haven't made any change

ComboInformation.SetFocus

If Not Me.NewRecord Then
     If Me.ComboInformation.ListCount = 0 Then
          'Clear info to force it to be updated
          On Error Resume Next 'Ignore inevitable error
          ComboInformation.Text = "" 'Set it to an invalid value
          ComboInformation= Null
          On Error GoTo PROC_ERR
      Else
          ComboInformation= ComboInformation.DefaultValue 'set it to a valid value
          End If
      End If
End If

如果用户选择的量没有有效的信息选择一个源,并随后选择创建方式,没有问题的新值。但是,如果他们决定导航回到ComboSource相反,他们得到一个错误信息,他们坚持完成ComboInformation,他们不能这样做。他们可以撤销他们提出要回了previous状态的变化,但这并不是一个直观的响应错误信息,告诉他们完成ComboInformation。

If the user selects a source for which there are no valid information choices, and then chooses to create a new value for Information, no problem. But if they decide to navigate back to ComboSource instead, they get an error message insisting they complete ComboInformation, which they can't do. They can undo the change they made to get back to the previous state, but that isn't an intuitive response to an error message telling them to complete ComboInformation.

有两种办法让他们导航回ComboSource时ComboInformation无效或另一种方式来逼迫他们节省,不存在此问题的记录之前更新ComboSource后更新ComboInformation?

Is there either a way to allow them to navigate back to ComboSource when ComboInformation is invalid or another way to force them to update ComboInformation after updating ComboSource before saving the record that doesn't have this issue?

更新有关该错误信息:我可以捕获它Form_Error虽然不产生错误信息出现 - 在堆栈中没有其他的手续。该错误信息是在信息表中的信息字段关联的消息(验证规则:不为null;确认文本;每一件证据必须来源于一个资料片)

Update about the error message: I can trap it in Form_Error although the error message isn't generated there -- no other procedures in the stack. The error message is the message associated with the Information field in the Information table (Validation rule: Is Not Null; Validation text; Every piece of evidence must derive from a piece of information)

进一步更新:我能处理错误(3316)在Form_OnError但会有场合不是我不想忽略一个有效的错误'...

Further update: I could handle the error (3316) in the Form_OnError but there will be occasions when isn't a 'valid error' that I don't want to ignore...

到目前为止已经试过其他的事情:

Other things tried so far:

刷新页面并没有帮助。

有一个数据库,演示在 HTTPS的问题:// S3- eu-west-1.amazonaws.com/genquiry/test.accdb

There's a database to demo the problem at https://s3-eu-west-1.amazonaws.com/genquiry/test.accdb

在数据库打开的唯一形式,将源设置为S3并尝试导航回到源选择不同的值。

Open the only form in the database, set the Source to S3 and attempt to navigate back to Source to select a different value.

推荐答案

一种可能性:

如果我设置ComboInformation和ComboInformation.DefaultValue为-1,而不是空的时候ComboInformation.Listcount = 0,这避免了触发表有效性规则(不为null),当用户返回到ComboSource。然而,它仍然是一个无效值(因为它打破表之间的数据的完整性)以及用户是从退出形式或保存记录,直到一个有效输入值pvented $ P $(通过选择对于源不同的值或创建在信息列表值)。

If I set ComboInformation and ComboInformation.DefaultValue to -1 rather than Null when ComboInformation.Listcount = 0, this avoids triggering the table validation rule (Is Not Null) when the user navigates back to ComboSource. However, it is still an invalid value (as it breaks data integrity between tables) and the user is prevented from exiting the form or saving the record until a valid value is entered (by choosing a different value for Source or creating a value in the Information list).

它的工作原理,但它不是一个完美的解决方案,并依赖于-1始终是在链接信息表自动生成的InformationID场,我不认为这是一个安全的假设无效值...

It works, but it isn't an elegant solution and depends on -1 always being an invalid value for the Automatically-generated InformationID field in the linked Information table, which I don't believe is a safe assumption...

不过,如果我修改方法略有找到最低的现有InformationID场(称之为LOWID),然后使用LOWID-1设置ComboInformation,这也适用,并且始终是在使用期间产生的无效值

However, if I modify the method slightly to find the lowest existing InformationID field (call this LOWID) and then use LOWID-1 to set ComboInformation, that also works, and always produces an invalid value for the period it is in use.

这篇关于如何强制访问组合框的更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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