0

I have data with a date that I want to exclude from my current data. I am trying to pull the required date from a sql table and compare it to the dates in the excel sheet.

The sql code is

Dim con As ADODB.Connection    
Dim rst As ADODB.Recordset    
DIM code_string as STRING  
code_string = "select date from table WHERE foo foo foo"

and the result is a date that I want to save in a variable.

I have tried Set rst = CurrentDb.OpenRecordset(strSQL) that I found here: How to save the result of a SQL query into a variable in VBA? and vba gives me an object required error.

Is there a way to save the results of a sql query in a vba variable?

JNevill
  • 46,980
  • 4
  • 38
  • 63
JoeJam
  • 371
  • 1
  • 14
  • 1
    You need to first open a recordset - would help to show the rest of your code: we can't tell much from one line. – Tim Williams Mar 16 '21 at 16:03
  • Have you added the ADODB library via Tools>>References? – JNevill Mar 16 '21 at 16:50
  • Here is what worked, thank you @TimWilliams `Set rs = con.Execute(code_string) Sheets("test").Range("A2").CopyFromRecordset rs` and I will compare everything to the value in A2 – JoeJam Mar 16 '21 at 17:53

0 Answers0