Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 使用具有多行的sql查询记录集填充多列列表框_Vba - Fatal编程技术网

Vba 使用具有多行的sql查询记录集填充多列列表框

Vba 使用具有多行的sql查询记录集填充多列列表框,vba,Vba,你的问题需要改进 也就是说,这是一个语法错误 Private Sub Combo13_AfterUpdate() Dim v1 As Variant: Dim i,i3, i1, i2 As Integer: Dim rst As Recordset v1 = Combo13.Value 'combo13 is the list box Set v1 = CurrentDb("Bills") 'bills is the table name

你的问题需要改进 也就是说,这是一个语法错误

Private Sub Combo13_AfterUpdate()
    Dim v1 As Variant: Dim i,i3, i1, i2 As Integer: Dim rst As Recordset
    v1 = Combo13.Value  'combo13 is the list box
    Set v1 = CurrentDb("Bills")   'bills is the table name
    Set rst = CurrentDb.OpenRecordset("select *  from bills where billnumber = " & Combo13.Value & ";")
    i1 = "select count(*) from bills where billnumber = " & Combo13.Value & ")"
    i2 = rst.Fields.Count
    For i = 1 To i1
        For i3 = 1 To 12
        With List6
             .AddItem rst.Fields(i2).Value 
              rst.MoveNext
        End With
        Next i2
    Next i1
    Set rst = Nothing   
End Sub
结束语
语法不正确

另外,
i1
是一个字符串-字符串中的查询没有在任何地方执行-您需要执行并从结果记录集中提取
i1
值,类似于前一行的代码
。。。CurrentDb.OpenRecordset…

Dim i、i3、i1、i2作为整数
仅将
i2
声明为整数。如果您想将所有数据都声明为整数,那么应该

i1 = "select count(*) from bills where billnumber = " & Combo13.Value & ")"

私有子组合13_AfterUpdate() Dim s1、s2作为字符串:Dim i、i1、i2、j作为整数:Dim rst作为记录集 Set rst=CurrentDb.OpenRecordset(“从billnumber=“&Combo13.Value&“;”)的票据中选择*) rst.MoveLast i2=rst.RecordCount i1=rst.Fields.Count 出错时继续下一步 对于i=List6.ListCount-1到0步骤-1 清单6.RemoveItem(一) 接下来我 i=0 rst.MoveFirst 对于i=1到i2 与列表6 对于j=1到i1 s2=s2和rst.字段(j)和“,” 下一个j .AddItem s2 rst.MoveNext 以 s2=“” 接下来我
End Sub

您有问题吗?
设置列表6.Recordset=rst
pl给出一个从具有多个列和行的sql查询结果填充列表框的示例
Dim i As Integer,i3 As Integer, i1 As Integer, i2 As Integer