Hello,
I used the recorder to help write a macro pulling data from a database into excel. I have the following code, which works as written:
However, when I try to clean up the code, in particular on the "WHERE" line, I get a run time 13 type mismatch error, hilighting the whole section of code listed above. I've tried cleaning up the "WHERE" line as follows:
I need to ultimately make some changes to the code in this line, but need to get rid of the error before I proceed. The macro ultimately displays the results as a pivot table.
Thanks for your help in this, as it is very perplexing to me.
I used the recorder to help write a macro pulling data from a database into excel. I have the following code, which works as written:
Code:
ActiveWorkbook.Connections.Add "Query from firm_prod", "", _
"ODBC;DSN=firm_prod;NA=firmprod1,6100;DB=db_firmprod;UID=X117913;", Array( _
"SELECT " _
& "report_field.choice1, report_field.choice2, report_field.choice3, report_field.choice4" _
& "FROM db_firmprod.dbo.report_field report_field" _
& "WHERE (report_" _
, _
"field.choice1='APPLE') AND (report_field.choice4>={ts '2011-06-30 00:00:00'} And report_field.choice4<={ts '2011-07-28 00:00:00'}) OR " _
& "(report_field.choice1='OR" _
, _
"ANGE') AND (report_field.choice4>={ts '2011-06-30 00:00:00'} And report_field.choice4<={ts '2011-07-28 00:00:00'}) OR " _
& "(report_field.choice1='PLUM') AND (report_f" _
, _
"ield.choice4>={ts '2011-06-30 00:00:00'} And report_field.choice4<={ts '2011-07-28 00:00:00'})" _
& "ORDER BY report_excess_return.choiceID, report_excess_return.asOfDate"), 2
However, when I try to clean up the code, in particular on the "WHERE" line, I get a run time 13 type mismatch error, hilighting the whole section of code listed above. I've tried cleaning up the "WHERE" line as follows:
Code:
& "WHERE (report_field.choice1='APPLE') AND (report_field.choice4>={ts '2011-06-30 00:00:00'} And report_field.choice4<={ts '2011-07-28 00:00:00'}) OR (report_field.choice1='ORANGE') AND (report_field.choice4>={ts '2011-06-30 00:00:00'} And report_field.choice4<={ts '2011-07-28 00:00:00'}) OR (report_field.choice1='PLUM') AND (report_field.choice4>={ts '2011-06-30 00:00:00'} And report_field.choice4<={ts '2011-07-28 00:00:00'})" _
I need to ultimately make some changes to the code in this line, but need to get rid of the error before I proceed. The macro ultimately displays the results as a pivot table.
Thanks for your help in this, as it is very perplexing to me.