多页--can';t验证框架内的选项按钮-excel VBA
我有一个两页的用户表单,目前都正常工作(几乎正常) 当我的用户点击第一页上的命令按钮时,我希望他们被发送到第二页,前提是选择了特定的选项按钮:多页--can';t验证框架内的选项按钮-excel VBA,vba,excel,Vba,Excel,我有一个两页的用户表单,目前都正常工作(几乎正常) 当我的用户点击第一页上的命令按钮时,我希望他们被发送到第二页,前提是选择了特定的选项按钮: If ProductEnquiryYes.Value = True Then Me.MultiPage1.Value = 1 closeForm = False Cells(emptyRow, 20).Value = 1 End If 因此,如果选中“产品查询”选项,他们应该转到下一页。 如果未选中“产品查询”选项,用户应结束表单。(选项卡标题将被隐
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
切换到第二页的代码行位于检查以确保表单已验证之前。如果要在执行任何其他操作之前确保满足这两个条件,则应将这段代码移到前面:
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
嗨,苏-又是高分了。谢谢我试着把它向上移动,但是把它放在你建议的地方。哎呀!至少我在正确的轨道上走了一半:PI有两个关于我的状态的最后问题。你觉得我们可以再聊一次吗?:)