多页 – 无法validation框架内的选项button – 卓越的VBA

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

当我的用户点击第一页上的命令button时,我希望它们被发送到第二页,只有当select了特定的选项button时:

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

所以,如果产品查询选项被选中 – 他们应该去下一页。 如果产品查询选项未被选中,用户应该结束表格。 (标签标题将被隐藏)

但是,我现在想validation第一页上的一个框架中的选项,以便每个框架内的选项必须被选中。 我几乎在那里,但如果用户没有select一个选项的警告出现,但用户转到下一页。 (即用户太晚了)

在这里输入图像说明

我需要的代码是检查选项button是否已被validation,然后才决定是否将我的用户发送到下一页或closures表单。

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

 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 

切换到第二页的代码行在检查之前,确保表单被validation。 如果你想确保在做其他事情之前满足这两个条件,你应该把这段代码移到更早的地方:

 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 ProductEnquiryYes.Value = True Then Me.MultiPage1.Value = 1 closeForm = False Cells(emptyRow, 20).Value = 1 End If