Ms access 访问VBA从列表框中选择多个值并执行查询名称

Ms access 访问VBA从列表框中选择多个值并执行查询名称,ms-access,listbox,vba,recordset,Ms Access,Listbox,Vba,Recordset,我的目的是让用户从列表框中选择一个或多个查询名称,并用这些名称提示执行查询 到目前为止,我有以下代码: Private Sub Command43_Click() Dim rs As DAO.Recordset Dim valSelect As Variant Dim strValue As String For Each valSelect In Me.Combo29.ItemsSelected strValue = strValue & "'" &

我的目的是让用户从列表框中选择一个或多个查询名称,并用这些名称提示执行查询

到目前为止,我有以下代码:

Private Sub Command43_Click()
  Dim rs As DAO.Recordset
  Dim valSelect As Variant
  Dim strValue As String

    For Each valSelect In Me.Combo29.ItemsSelected
    strValue = strValue & "'" & Me.Combo29.ItemData(valSelect) & "',"
    strValue = Left(strValue, Len(strValue) - 1)

    Set rs = CurrentDb.OpenRecordset(strValue)

    Debug.Print rs
   rs.Close
 Set rs = Nothing
 Next valSelect
MsgBox "Complete!"
End Sub
运行代码时,我得到一个错误,Access找不到查询名称


请帮忙

一个命令只能打开一个查询,请尝试:

For Each valSelect In Me!Combo29.ItemsSelected
    strValue = Me!Combo29.ItemData(valSelect)
    Set rs = CurrentDb.OpenRecordset(strValue)
    Debug.Print strValue, rs.RecordCount
Next
rs.Close
Set rs = Nothing

并将控件重命名为有意义的控件。

我在设置rs=CurrentDb.OpenRecordsetstrValue时收到一个错误,指出这是一个无效的操作。上面的代码只是带有循环的代码片段。您仍然需要调暗rs。rs已调暗,但同样的错误也出现了:Private子命令43_单击Dim rs As DAO.Recordset Dim valSelect As Variant Dim strValue As String For Each valSelect In Me.Combo29.ItemsSelected strValue=Me.Combo29.ItemDatavalSelect Set rs=CurrentDb.openrecordsettrvalue Debug.Print strValue,rs.RecordCount Next rs.Close Set rs=无MsgBox完成!End SubAnd valSelect是一个数字,strValue是一个字符串?valSelect是变量,strValue是一个字符串。但是,这里有一个更新我的代码,我管理它执行我需要的操作从列表框运行选定的查询名称,无论是单选还是多选-Private Sub Command43_单击Dim rs As DAO.Recordset Dim valSelect As Variant Dim strrvalue As String Set db=CurrentDb For Each valSelect In Me.Combo29.items selected DoCmd.SetWarningsWarningOff strValue=Me.Combo29.ItemDatavalSelect DoCmd.OpenQuery strValue Next DoCmd.setwarningsonmsgbox完成!端接头