Link to home
Start Free TrialLog in
Avatar of Eddie Antar
Eddie AntarFlag for United States of America

asked on

in TransferSpreadsheet, why can't I use extension .xlsx with acSpreadsheetTypeExcel12Xml OR acSpreadsheetTypeExcel12???

Hey experts,

I'm having a problem with some data I'm trying to export to Excel 2010. I'm allowing the user to use either the .xls or .xlsx extension. My code looks like this:

DoCmd.TransferSpreadsheet acExport, IIf(Right(txtExportPathAndFileName, 5) = ".xlsx", acSpreadsheetTypeExcel12Xml, acSpreadsheetTypeExcel12), "qryTherapistsCaseloads4Excel", txtExportPathAndFileName, True

When I try to open the exported .xlsx, I get a message that the extension or file type is invalid.

Any ideas?

Thanks
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

try using this for both file extension

DoCmd.TransferSpreadsheet acExport, 10, "qryTherapistsCaseloads4Excel", txtExportPathAndFileName, True

post back the result
I'd do it this way:

If Right(txtExportPathAndFileName, 5) = ".xlsx" Then
  DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml,"qryTherapistsCaseloads4Excel", txtExportPathAndFileName, True
Else
   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12,"qryTherapistsCaseloads4Excel", txtExportPathAndFileName, True
 End If

then put a stop on the IF and verify if the extension is on the end or not and that your falling through  the correct logic (use F8 to step through)

Jim.
Oh and BTW, acSpreadsheetTypeExcel12 is 2007 format, which still is normally an .xlsx extension.  You want acSpreadsheetTypeExcel8 for .XLS

Jim.
or this


If Right(txtExportPathAndFileName, 5) = ".xlsx" Then

DoCmd.TransferSpreadsheet acExport, 10, "qryTherapistsCaseloads4Excel", txtExportPathAndFileName, True

else

DoCmd.TransferSpreadsheet acExport, 9, "qryTherapistsCaseloads4Excel", txtExportPathAndFileName, True

end if
Avatar of Eddie Antar

ASKER

Arrggg! Driving me nuts!

I broke up my If statement up into an if then else and use the literal 10 for acSpreadsheetTypeExce12XML. I'm still getting the invalid message:

User generated image
Any ideas why this might be happening. This is a simple Transfer Spreadsheet call.

Any help would be greatly appreciated.

Thanks.
what access version are you using?
Access 2010.
try doing a compact and repair of your db then try again.

if the error still show,  upload a copy of your db
Hi Jim,

Yes, I read your post. Here's a picture of how I rewrote the code, but I'm still having the same problem.

User generated image
Any ideas??? It just shouldn't be.

Thanks.
can you upload a copy of the db?
can you test the code, using a table instead of the query "qryTherapistsCaseloads4Excel"
Hi Rey,

Uploading the db is a bit of a problem because I'm working with HIPPA compliant information. I'd have to dummy up some data.

But I just read something I'm going to try before I take that step.

Thank you.

E
what is the SQL statement of query "qryTherapistsCaseloads4Excel"?
He needs to be using acSpreadsheetTypeExcel8 for an .xls extension.

Jim.
@jim, he is already using it..
ASKER CERTIFIED SOLUTION
Avatar of Eddie Antar
Eddie Antar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Make sure you accept your own comment as answer.

Jim.
Thanks Jim. I always feel bad about doing that because I appreciate the company and feedback while I'm figuring this stuff out, even when I found the answer myself. But I know that those are the rules. Will do.
Found the answer through web search. Thanks again for sticking with me.