title: Access VB export certain query to designated filepath
body: <p>So I have a query named <code>"the query I wish to export"</code>, I want to be able to export the query to Excel when I click the button on my form. </p>
  
  <p>I created this function in <code>Module1</code> to call the dialog out and determine which file path I want to save my query result to.</p>
  
  <pre><code>Public Function ExportToExcel(strQuery As String)
  
      On Error GoTo Err_Handler
  
      Const MESSAGETEXT = "Overwrite existing file?"
      Dim OpenDlg As New BrowseForFileClass
      Dim strPath As String
  
      OpenDlg.DialogTitle = "Enter or Select File"
      strPath = OpenDlg.GetFileSpec
      Set OpenDlg = Nothing
  
      If strPath &lt;&gt; "" Then
          If Dir(strPath) &lt;&gt; "" Then
              If MsgBox(MESSAGETEXT, vbQuestion + vbYesNo, "Confirm") = vbNo Then
                  Exit Function
              Else
                  Kill strPath
              End If
          End If
      Else
          Exit Function
      End If
  
      DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12, strQuery, strPath
  
  Exit_Here:
      Exit Sub
  
  Err_Handler:
      MsgBox Err.Description
      Resume Exit_Here
  
  End Function
  </code></pre>
  
  <p>After complete this function, I call this function and wish to export my query to the filepath that I wish to select.</p>
  
  <pre><code>Private Sub Export1_Click()
  
      Call Module1.ExportToExcel "the query I wish to export"
  
  End Sub
  </code></pre>
  
  <p>It just keeps giving me <em>"Syntax Error"</em>. I don't really understand because I specifically call the function, passing the query name as its argument, any ideas?</p>