title: CommandText Not Runtime error 1004 in office 2013
body: <p>I have a code that should update the date in a sql query of a connection in excel. The date determines the table the data will come from. The code works without a problem in office 2016 on windows 10. However, I get runtime <strong>error</strong> </p>
  
  <blockquote>
    <p>1004: "application-defined or object-defined error”"</p>
  </blockquote>
  
  <p>on .CommandText line when I run the same macro in office 2013 on windows 8. </p>
  
  <p>Any ideas on how to solve this problem? </p>
  
  
  
  <pre><code>Sub change_date()
  
  Dim a As String, x As String, year As String, month As String, day As String, datebox As Variant
  
  'Get the day, month and year from name of the workbook
  x = ActiveWorkbook.Name
  year = Mid(x, 1, 4)
  month = Mid(x, 5, 2)
  day = Mid(x, 7, 2)
  
  'Ask user if he/she wants to change the date
      datebox = InputBox("Is the report date " &amp; _
      day &amp; "." &amp; month &amp; "." &amp; year &amp; _
      "?" &amp; vbNewLine &amp; vbNewLine &amp; _
      "If not, please enter the report date below as YYYY-MM-DD and click 'OK'." &amp; vbNewLine &amp; vbNewLine &amp; _
      "If that is the correct date, click 'OK' or 'Cancel' without entering anything below")
  If datebox = "" Then
      x = year &amp; "-" &amp; month &amp; "-" &amp; day
  Else
      x = datebox
  End If
  
  'Update the query with the report date
  With ActiveWorkbook.Connections("postgres y_original_customer_info").ODBCConnection
  a = "SELECT * FROM public.f_customers_with_pllm_and_gkh('"
  a = a &amp; x
  a = a &amp; "')"
  
  'Following line gives Runtime error 1004
  .CommandText = a
  
  'Following also gives error
  '.CommandText = Array("SELECT * FROM public.f_exposures_with_sllp_and_cqs('" &amp; x &amp; "')")
  
  .Refresh
  End With
  End Sub
  </code></pre>
  
  <p>I can't understand why the code doesn't work in office 2013. Any help would be appreciated. </p>