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

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

问题描述

(从输入的更广泛的问题缩小链接说明,按照建议在元中。 )

(Narrowed down from my broader question at enter link description here as advised in meta.)

我有一个用户窗体。该用户窗体是选择年,月和日的几个组合框。根据选择的年份和月份,当天组合框中填充数字最多为28,29,30或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错误的解释无法设置值属性。属性值无效。

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?

推荐答案

由于对reqs的误解:

Edit due to a misunderstanding of reqs:

我的错,我误解了原帖。如果日期是按照数字顺序设置的,那么确实可以使用 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天全站免登陆