收到“运行时错误'380":无法设置Value属性.无效的属性值."向组合框“值"属性分配值时出错 [英] Getting a "Run-time error '380': Could not set the Value property. Invalid property value." error when assigning a value to combobox 'value' property
问题描述
这里是设置:作为我正在开发的多个击球笼调度程序的一部分,数据字典(dReservData)加载了选定日期所有保留的数据.dReservData中加载了16个字段.当用户选择了特定的保留时,将使用数据字典中用于该保留的适当字段来加载表单上的控件.(为了简洁起见,我只包括了我认为是代码的相关部分.)运行时错误'380':无法设置Value属性.无效的属性值."当我尝试将值1(从Debug语句的输出中看到)分配给组合框(combo_ReservationsInstructor)的value属性时,会发生错误.组合框有2列,并预先填充了N x 2的教师ID和名称数组.我正在尝试使用分配给组合框的value属性的讲师ID(在本例中为ID"1")作为通过编程方式选择组合中的一项的方法.
Here's the setup: As part of a multiple batting cage scheduling program I am developing, a data dictionary (dReservData) is loaded with data for all the reservations for a selected date. There are 16 fields loaded into dReservData. When a specific reservation is selected by the user, controls on a form are loaded with the appropriate fields from the data dictionary for that reservation. (In the interest of brevity, I only included what I think is the relevant portion of the code.) The "Run-time error '380': Could not set the Value property. Invalid property value." error occurs when I try to assign the value 1 (which you can see from the output of the Debug statement) to the value property of a combobox (combo_ReservationsInstructor). The combobox has 2 columns and is pre-populated with an N x 2 array of Instructor ID's and Names. I am trying to use the assignment of an instructor ID (in this case, ID '1') to the combobox's value property as a means of programmatically selecting an item in the combo.
With form_APScheduler
.tb_ReservationsBeginTime.Value = dReservData(BegTime)(iStepRes)
.tb_ReservationsEndTime.Value = dReservData(EndTime)(iStepRes)
.tb_ReservationsNote.Value = dReservData(ResNote)(iStepRes)
If dReservData(RentType)(iStepRes) = "Lesson" Or dReservData(RentType)(iStepRes) = "CageRental" Then
If dReservData(RentType)(iStepRes) = "Lesson" Then
.combo_ReservationsType.Value = "Lesson"
Debug.Print "dReservData(ResInstructor)(iStepRes) = " & dReservData(ResInstructor)(iStepRes) 'Debug output: dReservData(ResInstructor)(iStepRes) = 1
.combo_ReservationsInstructor.Value = dReservData(ResInstructor)(iStepRes) '***ERROR OCCURS HERE
ElseIf dReservData(RentType)(iStepRes) = "CageRental" Then
.combo_ReservationsType.Value = "CageRental"
End If
推荐答案
使用 .Value
属性分配组合框的所选项目在所有情况下均无法很好地工作.尝试改用 .ListIndex
属性.
Assigning the selected item of a combobox with the .Value
property is not working in all the cases very well.
Try to use the .ListIndex
property instead.
在您的示例中,出现错误的行如下所示:
In your example the line where you get the error would look like:
.combo_ReservationsInstructor.ListIndex = dReservData(ResInstructor)(iStepRes) -1
注意:组合框的 ListIndex
开始以0开始计数...这就是在行尾使用 -1
的原因.
Attention: ListIndex
of a combobox is starting to count with 0... thats the reason for the -1
at the end of the line.
此解决方案假定讲师ID从1开始并且持续无间断
This solution is assuming that the instructor IDs are starting with 1 and are continuing without gaps
这篇关于收到“运行时错误'380":无法设置Value属性.无效的属性值."向组合框“值"属性分配值时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!