多页 - 无法验证框架内的选项按钮 - excel VBA [英] multipage -- can't validate option buttons inside a frame - excel VBA

查看:132
本文介绍了多页 - 无法验证框架内的选项按钮 - excel VBA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

 如果ProductEnquiryYes.Value = True然后
Me.MultiPage1.Value = 1
closeForm = False
单元格(emptyRow,20).Value = 1
结束如果

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



但是,我现在要验证第一页上的一个框架中的选项,以便必须选择每个框架内的一个选项。我几乎在那里,但是如果用户没有选择一个选项,则出现警告,但用户进入下一页。 (即用户得到警告太晚了)





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



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

  Private Sub CommandButton1_Click()

Dim emptyRow As Long

Dim closeForm As Boolean

'我们假设我们希望表单关闭,除非有理由去额外选项卡
closeForm = True


'确定emptyRow
emptyRow = WorksheetFunction.CountA(Range(A:A))+ 1

'客户询问产品?

如果ProductEnquiryYes.Value = True然后
Me.MultiPage1.Value = 1
closeForm = False
单元格(emptyRow,20).Value = 1
End If

如果ProductEnquiryNo.Value = True然后
单元格(emptyRow,21).Value = 1
如果

'=== ================================================== ====
'服务
'=============================== ====================

'余额查询
如果BalanceEnquiry.Value = True然后
单元格emptyRow,23).Value = 1
如果


'===================== =================================
'确保选择框架中的选项

如果Me.YesCustomerOption.Value = False和Me.NoCustomerOption.Value = False然后
MsgBox请确保您选择了客户是现有ASB客户的选项吗?,vbExclamation, 无法选择一个选项
Exit Sub
End If

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

'关闭Userform
如果closeForm然后卸载我


结束子


解决方案

切换到第二页的代码行在您的检查之前,以确保表单被验证。如果您想在执行其他任何操作之前确保满足这两个条件,则应将此部分代码移至更早版本:

 如果Me.YesCustomerOption.Value = False和Me.NoCustomerOption.Value = False然后
MsgBox请确保您选择了客户是现有ASB客户选项吗?,vbExclamation,无法选择一个选项
Exit Sub
End If

如果是两个初级支票,如果块在本节之前移动整体:

 如果ProductEnquiryYes.Value = True然后
我.MultiPage1.Value = 1
closeForm = False
单元格(emptyRow,20).Value = 1
如果


I have a two-page userform, all currently working correctly (almost).

When my users hit the command button on the first page, I want them to be sent to the second page, only if a specific option button is selected:

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

So, if the product enquiry option is checked - they should go to the next page. If the product enquiry option is not checked, users should end the form. (The tab headings will be hidden)

However, I now want to validate the options in a frame on the first page, so that an option inside each frame must be selected. I'm almost there, but if the users haven't selected an option the warning appears but the users go to the next page. (i.e. the users are getting the warning too late)

What I need my code to do is check that the option buttons have been validated BEFORE it decides whether or not to send my users to the next page or close the form.

Can someone help? Hopefully my question is clear.

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

解决方案

The line of code that switches to the second page is before your check to make sure the form is validated. If you want to make sure that these two conditions are met before doing anything else, you should move this section of code to be earlier:

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 those are the two primary checks, move that whole if block to be before this section:

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

这篇关于多页 - 无法验证框架内的选项按钮 - excel VBA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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