设置UserForm组合框的值 [英] Setting value of a UserForm Combobox

查看:122
本文介绍了设置UserForm组合框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(从输入的更广泛的问题中缩小链接描述,如在meta 中所述。 )

我有一个userform。在该用户窗体上有几个组合框用于选择年,月和日。根据选择的年份和月份,日期组合框中填充的数字最多为28,29,30或31。为避免选择2月31日之类的内容,我想检查所选日期值是否超过该月的最大值,并适当减少。目前我尝试过这些选项:

I have a userform. On that userform are several comboboxes for selection year, month and day. The day combobox is populated with numbers up to 28, 29, 30 or 31 depending on what year and month is selected. To avoid selecting things like the 31st of February, I'd like to check if the selected day value exceeds the maximum for that month, and reduce it appropriately. At the moment I've tried these options:

If Me.Combo_Day.Value > iMaxDate And iMonthNo > 0 And Not Me.Combo_Day.Value = "" Then Me.Combo_Day.Value = Me.Combo_Day.List(iMaxDate - 1)

If Me.Combo_Day.Value > iMaxDate And iMonthNo > 0 And Not Me.Combo_Day.Value = "" Then Me.Combo_Day.Value = iMaxDate

他们工作;任何时候该行被解析,我得到一个380错误解释无法设置Value属性。无效的属性值。

Neither of them work; any time that line gets parsed, I get a 380 error with the explanation "Could not set the Value property. Invalid property value."

我试图更改两个 .Text .Value ,似乎没有什么区别。 如何更改组合框中的选定值?

I've tried changing both .Text and .Value, and neither seem to make much difference. How do I change the selected value in a combobox?

推荐答案

我的错,我误解了原文。如果按照数字顺序设置日期,您可以使用 ListIndex (只记得它以零开头,因此您必须减1)。它将如下所示:

My fault, I misunderstood the original post. If the days are set in numerical order, you can indeed use the ListIndex (just remember it starts with zero, so you'll have to subtract 1). It would look like:

Me.Combo_Day.ListIndex =(iMaxDate - 1)

这是否有效?

这篇关于设置UserForm组合框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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