如何评估包含列名的字符串?

时间:2019-04-14 00:31:52

标签: vba eval ms-access-2016

由于我无法在表上附加条件格式,因此我需要一个抽象函数来检查一组记录或所有记录内部是否有错误,并将这些错误显示为表格和/或报告。

因为要在“标准”模式下实现此目标,我必须为表的字段定义规则[○每次我在控件或报表中使用该字段时,都需要重复该规则。很多时候,这些事情都是令人讨厌的,更不用说引入错误并导致维护噩梦了。

所以,我的想法是为CheckError表中的所有表及其行定义所有检查,例如与表'Persone'相关的以下片段:

TableName |      FieldName   |   TestNumber   |   TestCode                                    |   TestMessage                              |   ErrorType[/B][/COLOR]
Persone   | CAP              |       4        | len([CAP]) = 0 or isnull([cap])               | CAP mancante                               | warning
Persone   | Codice Fiscale   |       1        | len([Codice Fiscale]) < 16                    | Codice fiscale nullo o mancante            | error
Persone   | Data di nascita  |       2        | (now() - [Data di nascita]) < 18 * 365        | Minorenne                                  | info
Persone   | mail             |       5        | len([mail)] = 0 or isnull([mail]              | email mancante                             | warning
Persone   | mail             |       6        | (len([mail)] = 0 or isnull([mail])            | richiesto l'invio dei referti via e- mail, | error
          |                  |                |  and [modalità ritiro referti] = ""e-mail""   | ma l'indirizzo e-mail è mancante           |         
Persone   | Via              |       3        | len([Via]) = 0 or isnull([Via])               | Indirizzo mancante                         | warning

现在,在使用表Persona的每种表单或报表中,我想为函数设置一个'onload'属性

' to validate all fields in all rows and set the appropriate bg and fg color
Private Sub Form_Open(Cancel As Integer)      
    Call validazione.validazione(Form, "Persone", 0)
End Sub

' to validate all fields in the row identified by ID and set the appropriate bg and fg color
Private Sub Codice_Fiscale_LostFocus()
  Call validazione.validazione(Form, "Persone", ID)
End Sub

因此,在某一点上,函数validazione正好是表Persone的一行,并且在上面的[TestCode]列中描述了一组表达式。

现在,我需要在逻辑上针对表行评估TestString,以获取是非。

如果为true,则将字段的fg和bg颜色设置为正常 如果为false,我将根据上面的[ErrorType]列中的错误,信息或警告设置fg和bg颜色。


以上所有操作都很容易,准备就绪并且可以运行,除了上面的红色说明:

如何针对表行评估测试字符串以获取结果?

谢谢

保罗

0 个答案:

没有答案
相关问题