制作的Fileds强制性的,如果一个特定的申请被填充在Access表 [英] Make Fileds compulsory if a particular filed is filled in Access Form

查看:346
本文介绍了制作的Fileds强制性的,如果一个特定的申请被填充在Access表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在访问形式,在这里我想打3场(FYear , cboPeriodicity ,<$ <$ C C $> C $ c如果另一场 cboCompliance 由用户填写> cboPeriod )强制性的。

I have a form in access, where I want to make 3 fields (FYear, cboPeriodicity, cboPeriod) compulsory if another field cboCompliance is filled in by user.

我曾尝试以下code,我在哪里取消保存,如果其中任何一个字段为空。并且还可以通过 MSGBOX

I have tried the below code, where I am canceling save, if any of these fields are Empty. And also giving error message through msgBox

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Err

'Audit Data Values Set
Me.LastModifiedBy.Value = [TempVars]![currentUserID]
Me.LastModifiedTime.Value = Now()

'If Compliance value is filled, make other vaules compulsory
If IsNull(Me.cboCompliance.Value) Or Len(Me.cboCompliance.Value) <= 0 Then
    'DO nothing
Else
    Dim txtFiledisEmpty As String
    Dim wantToCancel As Boolean

    'Finiancial year ending
    If IsNull(Me.FYear.Value) Then
        wantToCancel = True
        txtFiledisEmpty = "If Compliance is selected, FY ENDING cannot be blank" & char(10)
        Me.FYear.SetFocus

    End If
    'Periodicity
    If IsNull(Me.cboPeriodicity.Value) Then
        wantToCancel = True
        txtFiledisEmpty = "If Compliance is selected, PERIODICITY cannot be blank" & char(10)
        Me.cboPeriodicity.SetFocus

    End If
    'Period
    If IsNull(Me.cboPeriod.Value) Then
        wantToCancel = True
        txtFiledisEmpty = "If Compliance is selected, PERIOD cannot be blank"
        Me.cboPeriod.SetFocus

    End If

    MsgBox "Error"
    Cancel = wantToCancel
End If

'Error Handling
Form_BeforeUpdate_Exit:
        Exit Sub
Form_BeforeUpdate_Err:
       MsgBox Error$
       Resume Form_BeforeUpdate_Exit

End Sub

我无法找到,问题出在哪里(约一个小时的调试后)。

I am unable to find (after an about hr of debugging), where the problem is.

在此先感谢。

推荐答案

有我的code一个愚蠢的错误。 字符应该是 CHR

There was a silly mistake in my code. Char should have been chr

在code的少许修改,以更好的消息。

The code was modified a little, to better messages.

Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo Form_BeforeUpdate_Err


'If Compliance value is filled, make other vaules compulsory
If IsNull(Me.cboCompliance.Value) Or Len(Me.cboCompliance.Value) <= 0 Then
    'DO nothing
Else
    Dim txtFiledisEmpty As String
    txtFiledisEmpty = "If Compliance is selected, " & Chr(10)
    Dim wantToCancel As Boolean
    wantToCancel = False

    'Period
    If IsNull(Me.cboPeriod.Value) Then
        wantToCancel = True
        txtFiledisEmpty = txtFiledisEmpty & " > PERIOD cannot be blank" & Chr(10)
        Me.cboPeriod.SetFocus
    End If

    'Periodicity
    If IsNull(Me.cboPeriodicity.Value) Then
        wantToCancel = True
        txtFiledisEmpty = txtFiledisEmpty & " > PERIODICITY cannot be blank" & Chr(10)
        Me.cboPeriodicity.SetFocus
    End If

    'Finiancial year ending
    If IsNull(Me.FYear.Value) Then
        wantToCancel = True
        txtFiledisEmpty = txtFiledisEmpty & " > FY ENDING cannot be blank" & Chr(10)
        Me.FYear.SetFocus
    End If

    If wantToCancel Then
        MsgBox txtFiledisEmpty
    End If

    Cancel = wantToCancel
End If

'Error Handling
Form_BeforeUpdate_Exit:
        Exit Sub
Form_BeforeUpdate_Err:
       MsgBox Error$
       Resume Form_BeforeUpdate_Exit

End Sub

这篇关于制作的Fileds强制性的,如果一个特定的申请被填充在Access表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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