I get the error
"Compile Error invalid use of ME keyword"
for the Excel VBA code below. I know from Googling that the cause is because you can't use "ME" in a module, but, I haven't been able to find anything on how to resolve it so it can work in the module.
What I am doing is I'm using VBA and SQL code and hitting a SQL database to bring back some information in pivot table form. But I just don't know how to resolve the ME problem.
Sub RefreshData()
Dim SQl As String
Dim startdate As String, Enddate As String
Dim pvt As PivotTable
Set pvt = **Me.**PivotTables("PivotTable5")
pvt.PivotCache.Connection = "ODBC;DSN=" & Application.Range("DSN_Source") & ";DATABASE=" & Application.Range("TD_DB") & ";"
startdate = Format(**Me**.Range("PSdate"), "yyyy-mm-dd hh:mm:ss")
Enddate = Format(**Me**.Range("PEdate"), "yyyy-mm-dd hh:mm:ss")
SQl = ""
SQl = "WITH PanDetail As " & vbCrLf
SQl = SQl & "( " & vbCrLf
SQl = SQl & " SELECT ID, name, SCODE, SDATETime, PDESCRIPTION, ROUND(VOLUME, 5) As VOLUME" & vbCrLf
SQl = SQl & ", ROUND(MASS, 0) As MASS " & vbCrLf