我在这里加载组合框的值,但我不想将ListIndex
属性设置为 -1。
Private Sub Form_Load()
OPENCON
RES.Open "DIVISION", CON, adOpenDynamic, adLockOptimistic, adCmdTable
If RES.RecordCount > 0 Then
RES.MoveFirst
For i = 0 To RES.RecordCount - 1
CmbDiv.AddItem RES.Fields("DIV").Value
CmbDiv.ItemData(CmbDiv.NewIndex) = RES.Fields("DIVID").Value
RES.MoveNext
Next
End If
RES.Open "HNM", CON, adOpenDynamic, adLockOptimistic, adCmdTable
If RES.RecordCount > 0 Then
RES.MoveFirst
For i = 0 To RES.RecordCount - 1
CmbHouse.AddItem Trim(RES.Fields("HOUSE").Value)
CmbHouse.ItemData(CmbHouse.NewIndex) = RES.Fields("HID").Value
RES.MoveNext
Next
End If
End Sub
这是我用来修改记录的代码。
Private Sub CmdSave_Click()
sql = "UPDATE STUDENT_RECORD_DATABASE SET "
sql = sql + "ROLLNO= " & Val(CmbRNO) & ","
sql = sql + "DIVID='" & Val(CmbDiv.ItemData(CmbDiv.ListIndex)) & "',"
sql = sql + "HID=" & Val(CmbHouse.ItemData(CmbHouse.ListIndex)) & " "
sql = sql + "WHERE ROLLNO= " & Val(CmbRNO) & ""
Set RES = CON.Execute(sql)
End Sub
在运行代码时,如果我同时修改了部门和房屋,那么没关系,但是当我让它们中的任何一个值(不修改值)时,它会在第 3 行和第 4 行显示错误CmdSave_Click
:
无效的属性数组值