Hello,
Using VBA code in excel, I'm looking to extract data from a SQL table. But I just need it to pull current year information from it. The code works fine without the WHERE statement, but that brings is the entire table when I'm just looking for current year stuff. When I add in the WHERE statement, I'm getting the following error message:
Run-time error '-2147217900 (80040e14)':
'now' is not a recognized built-in function name.
Sub UpdateData()
Dim conn As ADODB.Connection
Sheets("Input").Visible = True
Sheets("Input").Select
Range("A2:AE100000").ClearContents
Dim stFund, stYear As String
Dim rs As ADODB.Recordset
Dim stSQL As String
Set conn = New ADODB.Connection
conn.Open xConn
Set rs = New ADODB.Recordset
stSQL = "Select * from dData"
stSQL = stSQL & " WHERE Year([dDate]) = year(now())"
Set rs = conn.Execute(stSQL)
Range("A2").CopyFromRecordset rs
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Sheets("Input").Visible = False
End Sub