sql - Import Selected Columns to Excel from Access Table using VBA -


i trying import selected data access table. table has 4 columns , want want columns 2 , 3. in excel , want them listed in order: column 3, column 2 (reverse how in access). additionally want select rows (from access table) based on date referenced in excel spread sheet (which refer rpdate in code). in access, "date" first column. need please. thanks.

sub adoimportfromaccesstable() dim dbfullname string dim tablename string dim targetrange range dim rpdate range  dbfullname = "c:\documents\database.mdb" tablename = "datatable" targetrange = range("c5") rpdate = range("b2").value  dim cn adodb.connection, rs adodb.recordset, intcolindex integer     set targetrange = targetrange.cells(1, 1)     ' open database     set cn = new adodb.connection     cn.open "provider=microsoft.jet.oledb.4.0; data source=" & _         "c:\documents\database.mdb" & ";"     set rs = new adodb.recordset     rs         ' open recordset         .open tablename, cn, adopenstatic, adlockoptimistic, adcmdtable         ' records         .open "select * " & tablename & _             " [date] = rpdate, cn, , , adcmdtext"         ' filter rows based on date         rs.open , targetrange      end     rs.close     set rs = nothing     cn.close     set cn = nothing end sub 

try this

sub adoimportfromaccesstable() dim dbfullname string dim tablename string dim targetrange range dim rpdate range  dbfullname = "c:\documents\database.mdb" tablename = "datatable" set targetrange = range("c5") rpdate = range("b2").value  dim cn adodb.connection, rs adodb.recordset, intcolindex integer     set targetrange = targetrange.cells(1, 1)     ' open database     set cn = new adodb.connection     cn.open "provider=microsoft.jet.oledb.4.0; data source=" & _         "c:\documents\database.mdb" & ";"     set rs = new adodb.recordset     rs         ' open recordset         .open tablename, cn, adopenstatic, adlockoptimistic, adcmdtable         ' records         .open "select time, tank  " & tablename & " [date] = " & rpdate & " order tank, time", cn, , , adcmdtext         ' filter rows based on date                  end     rs.close     set rs = nothing     cn.close     set cn = nothing end sub 

this isn't prof sql injection, start


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -