Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 为空条件格式-MS Access窗体_Forms_Ms Access_Formatting_Conditional - Fatal编程技术网

Forms 为空条件格式-MS Access窗体

Forms 为空条件格式-MS Access窗体,forms,ms-access,formatting,conditional,Forms,Ms Access,Formatting,Conditional,我认为会发生很多事情… 我想知道是否有办法在Access的条件格式中格式化所有空白字段。在我的例子中,通常需要输入所有字段,但并非所有情况下都需要输入。因此,与其编写一堆条件代码来限制用户在其中写入,我只想在我的字段中添加一些红色背景,作为提醒:“嘿,这里什么都没有……你确定这就是你想要的吗?”它在平板电脑上,因此消息框会很烦人。条件格式就是这样。我知道你可以有“Is Null([Field]),但这需要我在30多个字段上检查我的20多个表单,并确保正确的字段名称等,然后分别为它们键入条件。是否

我认为会发生很多事情…

我想知道是否有办法在Access的条件格式中格式化所有空白字段。在我的例子中,通常需要输入所有字段,但并非所有情况下都需要输入。因此,与其编写一堆条件代码来限制用户在其中写入,我只想在我的字段中添加一些红色背景,作为提醒:“嘿,这里什么都没有……你确定这就是你想要的吗?”

它在平板电脑上,因此消息框会很烦人。条件格式就是这样。我知道你可以有“Is Null([Field]),但这需要我在30多个字段上检查我的20多个表单,并确保正确的字段名称等,然后分别为它们键入条件。是否有一种方法可以简单地多选择我的字段,在多个字段上执行条件格式,并使用“Is Equal:Null”?

我尝试过“等于:Null”,但它不起作用。.“等于:”(使用访问常量)也不起作用.想知道为什么?或者我该如何解决这个问题?而且,它只对非接触字段是必需的,所以如果用户开始键入,然后将其删除回空白,我不在乎;它可以保持无格式或返回红色,所以如果有更好的方法,我会全神贯注

编辑:我已经开始做一些VBA代码,我将把它们粘贴到我的所有表单中:

Private Sub Form_Load()
Dim ctl As Control
Dim reqCol As Long
Dim focusCol As Long
Dim doneCol As Long
Dim format As FormatCondition

reqCol = RGB(246, 180, 180)
focusCol = RGB(252, 249, 238)
doneCol = RGB(255, 255, 255)

For Each ctl In Me.Controls
    With ctl
        Me.Controls(ctl.Name).FormatConditions.Delete 'Delete the existing conditions.
        Me.Controls(ctl.Name).BackColor = doneCol 'Set the background color to the done color.

        Select Case .ControlType
            Case acTextBox
                'Create the format objects.
                format = Me.Controls(ctl.Name).FormatConditions.Add(acFieldValue, acEqual, "")
                format = Me.Controls(ctl.Name).FormatConditions.Add(acFieldHasFocus)

                'Format the filled in boxes (ie set back to red)
                With Me.Controls(ctl.Name).FormatConditions(0)
                    .BackColor = reqCol
                    .Enabled = True
                End With

                'Format the current field color (ie set to beige)
                With Me.Controls(ctl.Name).FormatConditions(1)
                    .BackColor = focusCol
                    .Enabled = True
                End With
        End Select
    End With
Next ctl
End Sub

问题是,
FormatConditions.Add(acFieldValue,acEqual,“”)
出于同样的原因不起作用……我该如何解决这个问题?因为VBA和内置条件都有缺陷,看起来像是一个bug。或者我前面缺少了一些东西。

将默认格式设置为希望显示零长度数据的方式。 使用

字段值大于

用于条件格式,并将该格式设置为字段中文本的显示方式


您可以在“设计”视图中按住Shift键并单击选择多个字段,以选择需要应用于解决的所有适当字段。将其放入我的表单中(可能会考虑将其作为一个模块;新加入此模块,但不确定如何解决)


诀窍是如何将它输入到
格式条件中。添加(…)
。它现在的工作方式正是我所希望的。

在Access 2016中,我无法找到@SeanC提供的默认格式选项。相反,我发现要使我的组合框正确格式化,我必须使用带ISNULL的表达式


将null与空字符串串联始终会生成空字符串。
len([Fieldname]&“)=0是否适用于您的任务?不太适用。它仍然保留了我必须手动输入[Fieldname]的事实对于每个字段。我需要一个批处理解决方案。我已经开始用VBA对其进行编码,但它也有相同的问题。将更新问题。这是我最初所做的,但它会导致一些小问题;在键入/导航时,它会闪烁为红色。它还使下拉菜单变为红色,无论是否已选择任何内容;难以阅读。我将尝试但小于“或0!
Private Sub Form_Load()
On Error Resume Next

Dim ctl As Control
Dim reqCol As Long
Dim focusCol As Long
Dim doneCol As Long
Dim format As FormatCondition
Dim expr As String

reqCol = RGB(246, 180, 180)
focusCol = RGB(252, 249, 238)
doneCol = RGB(255, 255, 255)

For Each ctl In Me.Controls
    With ctl
        'Delete the existing formatting
        Me.Controls(ctl.Name).FormatConditions.Delete
        Me.Controls(ctl.Name).BackColor = doneCol

        Select Case .ControlType
            Case acTextBox
                expr = "IsNull(" & ctl.Name & ") = True"
                'Create the format objects.
                format = Me.Controls(ctl.Name).FormatConditions.Add(acFieldHasFocus)
                format = Me.Controls(ctl.Name).FormatConditions.Add(acExpression, , expr)

                'Format the filled in boxes (ie set back to focus color)
                With Me.Controls(ctl.Name).FormatConditions(0)
                    .BackColor = focusCol
                    .Enabled = True
                End With

                'Format the current field color (ie set to required color)
                With Me.Controls(ctl.Name).FormatConditions(1)
                    .BackColor = reqCol
                    .Enabled = True
                End With
        End Select
    End With
Next ctl
End Sub