【问题标题】:multipage -- can't validate option buttons inside a frame - excel VBA多页 - 无法验证框架内的选项按钮 - excel VBA
【发布时间】:2014-07-11 14:18:53
【问题描述】:

我有一个两页的用户表单,目前都正常工作(几乎)。

当我的用户点击第一页上的命令按钮时,我希望他们被发送到第二页,前提是选择了特定的选项按钮:

 If ProductEnquiryYes.Value = True Then
Me.MultiPage1.Value = 1
closeForm = False
Cells(emptyRow, 20).Value = 1
End If

因此,如果选中产品查询选项 - 他们应该转到下一页。 如果未选中产品查询选项,用户应结束表单。 (标签标题将被隐藏)

但是,我现在想验证第一页上一个框架中的选项,因此必须选择每个框架内的一个选项。我快到了,但如果用户没有选择一个选项,则会出现警告,但用户会转到下一页。 (即用户收到警告为时已晚)

我需要我的代码做的是在它决定是否将我的用户发送到下一页或关闭表单之前检查选项按钮是否已经过验证。

有人可以帮忙吗?希望我的问题很清楚。

Private Sub CommandButton1_Click()

Dim emptyRow As Long

Dim closeForm As Boolean

' we assume we want the form closed unless there is a reason to go to the Extra tab
closeForm = True


'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1

'Did customer ask about product?

If ProductEnquiryYes.Value = True Then
Me.MultiPage1.Value = 1
closeForm = False
Cells(emptyRow, 20).Value = 1
End If

If ProductEnquiryNo.Value = True Then
    Cells(emptyRow, 21).Value = 1
End If

'=========================================================
'Services
'=========================================================

'Balance Enquiry
If BalanceEnquiry.Value = True Then
    Cells(emptyRow, 23).Value = 1
End If


'==========================================================
'Ensure Options in the frames are selected

If Me.YesCustomerOption.Value = False And Me.NoCustomerOption.Value = False Then
    MsgBox "Please ensure you have selected an option for 'Is the customer an existing ASB customer?'", vbExclamation, "Failed to select an option"
    Exit Sub
End If

'==========================================================

'Close Userform
If closeForm Then Unload Me


End Sub

【问题讨论】:

    标签: vba excel


    【解决方案1】:

    切换到第二页的代码行在您检查以确保表单已验证之前。如果你想在做任何事情之前确保这两个条件都满足,你应该把这部分代码移到更早的位置:

    If Me.YesCustomerOption.Value = False And Me.NoCustomerOption.Value = False Then
        MsgBox "Please ensure you have selected an option for 'Is the customer an existing ASB customer?'", vbExclamation, "Failed to select an option"
        Exit Sub
    End If
    

    如果这是两个主要检查,则将整个 if 块移动到此部分之前:

    If ProductEnquiryYes.Value = True Then
        Me.MultiPage1.Value = 1
        closeForm = False
        Cells(emptyRow, 20).Value = 1
    End If
    

    【讨论】:

    • Hi Sous - 再次获得最高分。谢谢。我尝试将其向上移动,但将其放在您建议的位置下方。哎呀!至少我有一半是在正确的轨道上:P
    • 我有两个关于我的表格的最后问题。你觉得我们还能再聊天吗? :)
    猜你喜欢
    • 1970-01-01
    • 2013-03-08
    • 1970-01-01
    • 2019-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多