iamnamja
asked on
How to use ADO to query changed data in same workbook
Hi,
I have a spreadsheet that first queries a database and stores the values in sheet1. Then I have a separate process that queries this sheet through ADO and outputs the result in sheet2.
For some reason it seems like the ADO query is taking the result from the saved spreadsheet therefore returning old data, instead of taking the data from the open sheet.
How can I make the ADO query take the "live" data from the open sheet, instead of taking it from the saved data?
I have a spreadsheet that first queries a database and stores the values in sheet1. Then I have a separate process that queries this sheet through ADO and outputs the result in sheet2.
For some reason it seems like the ADO query is taking the result from the saved spreadsheet therefore returning old data, instead of taking the data from the open sheet.
How can I make the ADO query take the "live" data from the open sheet, instead of taking it from the saved data?
summary_ws.Cells.ClearContents
With objCon
.Provider = "Microsoft.ACE.OLEDB.12.0"
.Properties("Extended Properties").Value = "Excel 12.0;HDR=Yes;IMEX=1"
.Open wb.FullName
End With
globSQL = "SELECT id, InsType, gInsType " & _
"FROM [output$] " & _
"WHERE InsType <> gInsType "
globRS.Open globSQL, objCon
y = 1
For Each fld In globRS.Fields
summary_ws.Cells(1, y).Value = fld.Name
y = y + 1
Next
summary_ws.Cells(2, 1).CopyFromRecordset globRS
ASKER
Nope. That's the thing. I don't recall ever having to save the spreadsheet.
Or possibly a better question is.. Is there a way to do this without saving? I need to query what's on the sheet rather than having to save since this spreadsheet is used by multiple users.
Or possibly a better question is.. Is there a way to do this without saving? I need to query what's on the sheet rather than having to save since this spreadsheet is used by multiple users.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm willing to move away from ADO. I just need a way to query the latest result without saving if possible.
Could "Sheet2" use a direct ADO connection to the (same) database (without the intervening step via "Sheet1")?
ASKER
Basically what this macro does is it connects to two different databases and pulls the results out into output sheet
then the summary sheet's ado query takes what's there and does a comparison to output only the ones that are not matching.
then the summary sheet's ado query takes what's there and does a comparison to output only the ones that are not matching.
...Could you implement that as a single SQL Statement (LEFT/INNER) JOINing one database to the other?
ASKER
No... One database is in oracle, and the other is in sybase. no way to query both at the same time... that's why i'm using this to grab the data, then do the comparison in excel
ExcelApp.ActiveWorkbook().