I need to reference a cell that has a date on the sql code using VBA
<p>So I have an Excel sheet that has a start date and end date that can be changed by the user. I have a second sheet that has a cell in which the user can input his query in order to get that information. I have assigned startDate and enDate to the query so it can reference those cells. The problem I am having is that because I am extracting the query from excel it does not reference the startdate and endate. Is there something I can do to fix this? Here is the query:</p>

<pre><code>select system_date where system_date &gt;= ' " &amp; startDate &amp; "" and
system_date &lt;= "" &amp; endDate &amp; "# and action_id = 15 and log_desc not
like '%svc_openlink_p%' order by system_date
</code></pre>

<p>Here is the code: </p>

<pre><code>Sub Button1_Click()
Dim dbConnectStr As String
Dim dbConnectStr1 As String
Dim objmyconn As ADODB.Connection
Set objmyconn = New ADODB.Connection
Dim recordCount As Long
Dim sh1 As Worksheet, s2 As Worksheet
Dim j As Long, N As Long, r1 As Range
Dim dat As Variant
Dim Rng As Range
Dim startDate   As String
Dim endDate As String
Dim dataName As String
Dim passWord As String
Dim serverName As String
Dim qryN As String




'code for the dates
startDate = Format(Worksheets("TotalExtraction").Range("C6").Value2, "dd-mmm-yyyy")
endDate = Format(Worksheets("TotalExtraction").Range("C8").Value2, "dd-mmm-yyyy")

'code for assigment

dataName = (Range("dataName").Value)
passWord = (Range("password").Value)
serverName = (Range("server").Value)
qryN = (Range("Query").Text)

dbConnectStr = "Provider=msdaora;User Id=" &amp; Uname
dbConnectStr1 = "Provider=msdaora;User Id='" &amp; dataName &amp; "';Data Source='" &amp; serverName &amp; "';Pwd='" &amp; passWord &amp; "'"

    objmyconn.ConnectionString = dbConnectStr &amp; dbConnectStr1
    objmyconn.Properties("Prompt") = adPromptAlways
    objmyconn.Open dbConnectStr 'ConnectionString'
    'Declare variables'

'Set objmyconn = New ADODB.Connection
Set Sql = New ADODB.Command
Set ds = New ADODB.Recordset
Dim strsql As String
Dim fld As ADODB.Field
Dim i As Long
i = 2

Worksheets("IndividualUsers").Activate
ActiveSheet.Range("B4:M30000").Clear

        'Set and Execture SQL Command
Set Sql.ActiveConnection = objmyconn
Sql.CommandText = qryN
MsgBox qryN
Sql.CommandType = adCmdText
Sql.Execute
</code></pre>