vb中数据自动填写?

来源:百度知道 编辑:UC知道 时间:2024/06/27 04:42:27
用户档案新增窗口中combo控件与产品管理表连接,在购买机型中通过combo控件选择机型,在text控件中显示相应的配置
Private Sub comGMJX_Click()
SQL1 = "select * from 产品管理表 "
Call OpenConn
rs.Open SQL1, cn, 1, 1
iIndex = 0
Do While Not rs.EOF
Me.comGMJX.AddItem rs.Fields(2)
ReDim Preserve sBaseSet(iIndex)
ReDim Preserve xBaseSet(iIndex)
sBaseSet(iIndex) = rs.Fields(3).Value
xBaseSet(iIndex) = rs.Fields(4).Value
iIndex = iIndex + 1
rs.MoveNext
Loop

Me.txtJBPZ.Text = sBaseSet(comGMJX.ListIndex)
Me.txtDJ.Text = xBaseSet(comGMJX.ListIndex)
Call CloseConn

出现下标越界问题
为什么调试时Me.txtJBPZ.Text = sBaseSet(comGMJX.ListIndex)
这一句出错。

刚开始时comGMJX.ListIndex默认为-1吧?是不是应该先让它选中第一项?
不知道你的XbaseSet下标是从0开始的还是从1开始的,自己看一下
comGMJX.ListIndex=0
Me.txtJBPZ.Text = sBaseSet(comGMJX.ListIndex)
最方便的是用DataList/DataCombo控件了,你去看一下这个控件的资料