2012-02-03 5 views
0

두 개의 매개 변수를 기반으로 Access에서 Excel로 데이터를 가져 오려고합니다. 프로젝트 번호 (매개 변수 1)와 도구 유형 (매개 변수 2)을 지정하는 도구 목록이 있습니다. 이 두 매개 변수의 사용자 입력을 만족시키지 못하는 도구를 필터링하려면 어떻게합니까? 두 개의 매개 변수를 기반으로 Access 테이블에서 Excel로 가져 오기

나는이 스레드 보았다 Import to Excel from Access table based on parameters

을하지만 여러 매개 변수에 대해 이야기하지 않습니다. 내가 초점을 얻고 SelectedProj에 값을 삽입 할 필요가 어디

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 문입니다 : 내가 지금까지에 어딘지 여기에있다.

감사합니다.

답변

1

그냥 SQL 문에 SelectedProj를 추가하고 싶다면,이 (ProjectType 필드의 이름입니다) 트릭해야한다 : 항목을 선택하면

strSQL = "SELECT * " _ 
     & "FROM ToolFiles " _ 
     & "WHERE Tool_Name = '" & SelectedTool & "' " _ 
     & "AND ProjectType = '" & SelectedProj & "'" 
0

선택한 속성은 True를 반환 위의 예에서는 의미가 없습니다. 아마 당신은 당신이 또한 장난 꾸러기입니다 SelectedTool에 대한 선언이없는

SelectedTool = Tools_listbox.Items(Tools_listbox.SelectedItem) 

주처럼 뭔가를 찾고있다하지만 난 당신이 설정을 사용하지 말아야하는 경우 문자열이어야한다 같아요.

관련 문제