Connecting Tech Pros Worldwide Forums | Help | Site Map

TransferSpreadsheet Method and SQL

Brad
Guest
 
Posts: n/a
#1: May 15 '06


Thanks for taking the time to read my question.

I want to use SQL in the TransferSpreadsheet Method, but I can't get it
to work.

I don't know why, because I've done a debug.pring on the same code to
see what the code resolves to and it looks just like the select
statement in the query I based it on.

I want SQL in there so that it can be dynamic. Any table, and any date
field in that table.


Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8,
  2. "SELECT " & Me.cboTableNames & ".*, " & Me.cboTableNames & "." &
  3. Me.cboDateFields & " " & _
  4. "FROM " &
  5. Me.cboTableNames & _
  6. "WHERE ((("
  7. & Me.cboTableNames & "." & Me.cboDateFields & ") Between #" &
  8. Me.txtStartDate & "# And #" & Me.txtEndDate & "#));", Me.txtSaveTo & "\"
  9. & Me.txtFileName
  10.  
  11.  

The error I get is: Error Number 3011, The Microsoft Jet Database Engine
could not find the object 'the sql I wrote goes in here'. Make sure the
object exists and that you spell its name and the path name correctly.

Thanks again for your help.

Brad

*** Sent via Developersdex http://www.developersdex.com ***

fredg
Guest
 
Posts: n/a
#2: May 15 '06

re: TransferSpreadsheet Method and SQL


On Mon, 15 May 2006 17:57:40 GMT, Brad wrote:
[color=blue]
> Thanks for taking the time to read my question.
>
> I want to use SQL in the TransferSpreadsheet Method, but I can't get it
> to work.
>
> I don't know why, because I've done a debug.pring on the same code to
> see what the code resolves to and it looks just like the select
> statement in the query I based it on.
>
> I want SQL in there so that it can be dynamic. Any table, and any date
> field in that table.
>
>
Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel8,
  2. > "SELECT " & Me.cboTableNames & ".*, " & Me.cboTableNames & "." &
  3. > Me.cboDateFields & " " & _
  4. >                                                              "FROM " &
  5. > Me.cboTableNames & _
  6. >                                                              "WHERE ((("
  7. > & Me.cboTableNames & "." & Me.cboDateFields & ") Between #" &
  8. > Me.txtStartDate & "# And #" & Me.txtEndDate & "#));", Me.txtSaveTo & "\"
  9. > & Me.txtFileName
  10. >
>
> The error I get is: Error Number 3011, The Microsoft Jet Database Engine
> could not find the object 'the sql I wrote goes in here'. Make sure the
> object exists and that you spell its name and the path name correctly.
>
> Thanks again for your help.
>
> Brad
>
> *** Sent via Developersdex http://www.developersdex.com ***[/color]

i believe you must use a named database object (table or query).
Create a query, using your SQL.
Use the query name (in quotes) in place of your SQL.


--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Closed Thread