Exporting to Excel

J

Jazz57

Good afternoon

i have some data on a Query that i want to transfer to Excel.

I have allready my command but i want the file from the path to be achieved
by a construction and concatenated with the rest of the path.

Explaning with the code:

Private Sub CmdExcel_Click()

Dim ficheiro As String
Dim anof, mesf As String

anof = Year(Date)
mesf = Month(Date)

ficheiro = "AVD" & anof & mesf & ".xls"

DoCmd.TransferSpreadsheet acExport, , "QDadosParaExcel", "C:\Producao\"
& "ficheiro"", yes, , True"

-----------------------------------------
When i put a debug.print instruction after it is created the ficheiro , i
received the following name: AVD200712.xls which is correct

When i try to make it works with the instruction i have it doesn't work and
i receive the message:

Run-Time error '3436'

Failed on creating the file

I suppose this message has something to do with the process that i made to
construct the name of my file.

Hope that someone can help me

Many thanks in advance for the help and support

End Sub
 
J

John Nurick

DoCmd.TransferSpreadsheet acExport, , "QDadosParaExcel", "C:\Producao\"
& "ficheiro"", yes, , True"

The quote marks " round "ficheiro" and afterwards are incorrect. Also,
you seem to be trying to pass True to the UseOA argument. As far as I
can tell this does not do anything (the Access 2003 documentation here
http://msdn2.microsoft.com/en-us/library/aa220766(office.11).aspx says
it is not supported). Try this:

DoCmd.TransferSpreadsheet acExport, , "QDadosParaExcel", _
"C:\Producao\" & ficheiro, True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top