[求助]请问在vba里listbox控件怎么总是有问题?
<p>下面这段代码我在vb6.0里运行没问题怎么到vba里就不行了呢?总是提示:“无法获取list属性、属性阵列索引无效</p><p>Private Sub UserForm_Layout()<br/>Dim sjk As New ADODB.Connection<br/>Dim sjklj As String<br/>Dim dwzd As New ADODB.Recordset<br/>Dim dwjs As Double<br/>Dim zd() As String<br/>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj<br/>dwzd.Open "select aa=count(dwid) from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>If Not dwzd.EOF Then<br/> dwjs = dwzd.Fields("aa")<br/>End If<br/>dwzd.Close<br/>dwzd.Open "select * from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>ReDim zd(dwjs) As String<br/>i = 0<br/>Do While Not dwzd.EOF<br/> i = i + 1<br/> zd(i) = dwzd.Fields("dwname")<br/> dwzd.MoveNext<br/>Loop<br/>For j = 0 To i<br/> ListBox1.List(j) = zd(j + 1) '此处总是提示“无法获取list属性、属性阵列索引无效<br/>Next j</p><p>End Sub</p> 去到最后一位循环时,J+1已经大于I了,肯定会无效。 本帖最后由 作者 于 2007-10-23 12:58:06 编辑 <br /><br /> <strong><p><strong>程序报错</strong></p></strong><p><strong>实时错误未发现数据源名称并且未指定默认驱动程序</strong></p><p>程序出错的位置</p><p>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj------------------------------错在这里</p><p>连接库Data Source=hbcad?????????????????<br/></p><p></p><p></p><p>---------------------</p><p>Private Sub UserForm_Layout()<br/>Dim sjk As New ADODB.Connection<br/>Dim sjklj As String<br/>Dim dwzd As New ADODB.Recordset<br/>Dim dwjs As Double<br/>Dim zd() As String<br/>sjklj = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=hbcad"<br/>sjk.Open sjklj<br/>dwzd.Open "select aa=count(dwid) from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>If Not dwzd.EOF Then<br/> dwjs = dwzd.Fields("aa")<br/>End If<br/>dwzd.Close<br/>dwzd.Open "select * from tyname", sjk, adOpenDynamic, adLockBatchOptimistic<br/>ReDim zd(dwjs) As String<br/>i = 0<br/>Do While Not dwzd.EOF<br/> i = i + 1<br/> zd(i) = dwzd.Fields("dwname")<br/> dwzd.MoveNext<br/>Loop<br/>For j = 0 To i<br/> ListBox1.List(j) = zd(j + 1) '此处总是提示“无法获取list属性、属性阵列索引无效<br/>Next j</p><p>End Sub</p> 二楼正解,我试过类似问题对的
页:
[1]