【发布时间】:2012-02-26 09:55:13
【问题描述】:
我正在尝试基于两个参数将数据从 Access 导入 Excel。我有一个工具列表,其中指定了项目编号(参数 1)和工具类型(参数 2)。如何过滤掉不满足用户输入这两个参数的工具?
我看到了这个帖子:Import to Excel from Access table based on parameters
但它没有谈论多个参数。这是我目前所处的位置:
Dim cn As Object
Dim rs As Object
Dim strFile As String
Dim strCon As String
Dim strSQL As String
Dim s As String
Dim i As Integer, j As Integer
''Access database
strFile = "D:\Tool_Database\Tool_Database.mdb"
''This is the Jet 4 connection string, you can get more
''here : http://www.connectionstrings.com/excel
strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strFile & ";"
''Late binding, so no reference is needed
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")
cn.Open strCon
'Find the name of the tool that was selected
Dim SelectedTool As String, SelectedProj
Set SelectedTool = Tools_ListBox.Selected
Set SelectedProj = Project_ListBox.Selected
strSQL = "SELECT * " _
& "FROM ToolFiles " _
& "WHERE Tool_Name = '" & SelectedTool & "'"
rs.Open strSQL, cn, 3, 3
Worksheets("ToolList").Cells(2, 1).CopyFromRecordset rs
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
显然 strSQL 语句是我需要集中注意力并将值插入 SelectedProj 的地方。
谢谢!
【问题讨论】: