title: Access vba code not exporting to EXCEL "Too few parameters. Expected 1."
body: <p>I have some code I previous got from one of my other Access Databases, which works fine. It intended purpose was to copy the results that were put into a make table into a blank excel sheet then format the columns. </p>
  
  <p>I however copied the code and tweaked it a little. What I am trying to do with the copied code is still export my results into a blank excel sheet, however, this time I am not coping from a make table but from a select query. I am not sure if it is possible but there is no other way for me to make this into a make table, it has to be an select query. Is there any way someone can help? The code I have now is:</p>
  
  <pre><code>Option Compare Database
  Public Function Export_EXCEL()
  
  
  Dim dbs As DAO.Database
  Dim Response As Integer
  Dim strSQL As String
  Dim Query1 As String
  Dim LTotal As String
    Dim Excel_App As Excel.Application 'Creates Blank Excel File
    Dim strTable As String ' Table in access
      Dim queryDelete As String 'SQL to delete records in local table
      Dim strAssigned As DAO.Recordset
  
  '-------------------------------------------------------------------------------
  strTable = "Select * From cso_sup_SETUP" 'Access Query I am trying to copy
  
      Set Excel_App = CreateObject("Excel.Application")
          Set dbs = CurrentDb
  '-------------------------------------------------------------------------------
  Dim rs As DAO.Recordset
  Set rs = dbs.OpenRecordset(strTable)
  
      Excel_App.Visible = True
  
  Dim wkb As Excel.Workbook
    Set wkb = Excel_App.Workbooks.Add
  
  Dim rg As Excel.Range
  Dim i As Long
  ' Add the headings
  For i = 0 To rs.Fields.Count - 1
      wkb.Sheets(1).Cells(1, i + 1).Value = rs.Fields(i).Name
  Next i
  
  Set rg = wkb.Sheets(1).Cells(2, 1)
  rg.CopyFromRecordset rs
  
  ' make pretty
  rg.CurrentRegion.EntireColumn.AutoFit
  
  
  Set rs = Nothing
  Set wkb = Nothing
  Set dbs = Nothing
  
  End Function
  </code></pre>
  
  <p>This is the modified code below:</p>
  
  <pre><code>Option Compare Database
  Public Function Export_EXCEL()
  
  
  Dim dbs As DAO.Database
  Dim Response As Integer
  Dim strSQL As String
  Dim Query1 As String
  Dim LTotal As String
    Dim Excel_App As Excel.Application 'Creates Blank Excel File
    Dim strTable As String ' Table in access
     Dim queryDelete As String 'SQL to delete records in local table
     Dim strAssigned As DAO.Recordset
  
   Dim rs As DAO.Recordset
   Dim db As DAO.Database
   Dim prm As DAO.Parameter
   Dim qdf As DAO.QueryDef
  
   '-------------------------------------------------------------------------------
   strTable = "Select * From cso_sup_SETUP" 'Access Query I am trying to copy
  
  Set Excel_App = New Excel.Application
      Set dbs = CurrentDb
   '-------------------------------------------------------------------------------
  
  Set rs = QuerDef.OpenRecordset(strTable)
  
  Excel_App.Visible = True
  
  Dim wkb As Excel.Workbook
    Set wkb = Excel_App.Workbooks.Add
  
  Dim rg As Excel.Range
  Dim i As Long
   ' Add the headings
  For i = 0 To rs.Fields.Count - 1
     wkb.Sheets(1).Cells(1, i + 1).Value = rs.Fields(i).Name
   Next i
  
  Set rg = wkb.Sheets(1).Cells(2, 1)
  rg.CopyFromRecordset rs
  
  ' make pretty
  rg.CurrentRegion.EntireColumn.AutoFit
  
  
   Set rs = Nothing
   Set wkb = Nothing
   Set dbs = Nothing
  
   End Function
  </code></pre>