2017-08-31 149 views
1

我试图用一个事件之前要取消选择一个选项组。取消选项组按钮

用户是指选项组中选择一个值之前,输入一个名称。如果他们去并输入一个名称之前选择一个值,他们得到一个消息框,选项组中取消选择。

我已经尝试设置选项组值设置为null但只是抛出了运行时错误。

任何想法?提前致谢。

Private Sub og_name_BeforeUpdate(Cancel As Integer) 
Dim strName As String 

strName = txt_Customer_Name 

If strName = "" Then 

    MsgBox "Name is not entered" 

    og_name.Value = Null 

End If 
End Sub 

编辑:该选项组需要取消选择它的工作。当没有填写strName的情况下选择一个选项时,消息框应该出现。 然而,之前更新事件不断,当我尝试,因为该选项仍处于选中状态,选择别的东西运行。这让我处于一个试图选择别的东西的循环中,但会收到消息框的提示。

回答

2

您可以使用一些复杂的不选的东西,或者你可以使用Before Update事件,这是更简单的Cancel参数。

通过设置CancelTrue,您取消挂起的更新。它不主动取消选择某件事。

If strName = "" Then 

    MsgBox "Name is not entered" 
    Cancel = True 
    txt_Customer_Name.SetFocus 'move focus from the option group, per your edit 
End If 
+0

试过,但我仍然得到消息框,选项组仍处于选中状态。 – patreilly

+0

尝试在当前编辑 –

0

值设置为0

If Len(strName & "") = 0 Then 'This will also capture nulls 

    MsgBox "Name is not entered" 
    Cancel = true 
    Me.og_name = 0 

End If 
+0

试过,但我仍然得到消息框,选项组仍处于选中状态 – patreilly

+0

选项组设置为0,肯定会取消它,我已经尝试过了一对夫妇的形式。 - 我已经添加了cancel = true。 – Minty