Export to Excel: help now getting a bit urgent!

S

scubadiver

I have posted twice in the "import/export" forum and Mr Steele has given me a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
K

Ken Snell \(MVP\)

Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"
 
S

scubadiver

That is what the code was originally and I still get the same error. Is
there an alternative?




Ken Snell (MVP) said:
Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




scubadiver said:
I have posted twice in the "import/export" forum and Mr Steele has given me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
S

scubadiver

I haven't come across this error before. Where else would I look?




Roger Carlson said:
Error 438 is an automation error (Object doesn't support this property or
method). Even though it errors on line 3, that may not be what's causing
the error. You may need to look elsewhere.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

scubadiver said:
I have posted twice in the "import/export" forum and Mr Steele has given me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
R

Roger Carlson

That's hard to say. Automation errors are some of the trickiest to debug.
Look at other parts of your code that reference external objects. But it
could even be a problem with your References or even corruption in the
database itself causing it. But start by looking closely at the rest of
your code.

If you can't find anything in your code, try repairing or even decompiling
your database. The safest way to decompile is to create a brand new
database and import ALL objects (including import/export specs) to the new
database.

I'm sorry I can't be more helpful.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

scubadiver said:
I haven't come across this error before. Where else would I look?




Roger Carlson said:
Error 438 is an automation error (Object doesn't support this property or
method). Even though it errors on line 3, that may not be what's causing
the error. You may need to look elsewhere.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L

scubadiver said:
I have posted twice in the "import/export" forum and Mr Steele has given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
T

Tom Wickerath

Hi Scuba,

I'm a bit confused by your reference to the third line, since you've only
shown one line of VBA code. The space underscore ( _) line continuation
characters mean that this is all one line of code. A couple of suggestions:

1.) Declare string variables and assign the appropriate values. Use
Debug.Print statements to verify that the results look reasonable. For
example:

Dim strFileName As String
Dim strSavePath As String
Dim strFullPath As String

strFileName = [Forms]![menu]![Reports menu].Forms![SavePath]
strSavePath = "S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\" _
& "Queries Database 2007\New Database\"
strFullPath = strSavePath & strFileName & "\.xls"

Debug.Print "FileName: " & strFileName
Debug.Print "Path: " & strSavePath
Debug.Print "FullPath: " & strFullPath

Using a test spreadsheet saved in the intended path, with a pre-determined
name, you should be able to copy the FullPath from the Immediate Window,
paste it into the search box for finding Files or Folders, and locate this
file successfully.

2.) Use your new variable in the DoCmd.TransferSpreadsheet line:

DoCmd.TransferSpreadsheet TransferType:=acExport, _
TableName:="Report_Errors", FileName:=strFullPath, _
HasFieldNames:=True

Note: The "Errors" at the end of your line of code seems to correspond to
the optional UseOA argument, which I'm not sure has any real use.

3.) Verify that you have included the two very important words "Option
Explicit" as the second line of code at the top of your module:

Option Compare Database
Option Explicit

For more information on this, please see the following link:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions

4.) Verify that your code compiles without any errors. With any code module
open, click on:
Debug > Compile ProjectName

where ProjectName is the name of your VBA project.

5.) I recommend substituting the Uniform Naming Convention (UNC) path, in
place of the hard-coded drive letter "S:". That way, your code will not be
dependent on each user having the S drive correctly mapped.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

I have posted twice in the "import/export" forum and Mr Steele has given me a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
K

Ken Snell \(MVP\)

You have an improper reference to the subform's control (you're using Forms
and it should be Form):

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , , "Errors"

Also, be sure that "Reports menu" is the name of the subform control that
actually holds the subform.

--

Ken Snell
<MS ACCESS MVP>




scubadiver said:
That is what the code was originally and I still get the same error. Is
there an alternative?




Ken Snell (MVP) said:
Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




scubadiver said:
I have posted twice in the "import/export" forum and Mr Steele has given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
S

scubadiver

Ah yes. I hope it isn't that simple! Will check on Tuesday.


Ken Snell (MVP) said:
You have an improper reference to the subform's control (you're using Forms
and it should be Form):

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , , "Errors"

Also, be sure that "Reports menu" is the name of the subform control that
actually holds the subform.

--

Ken Snell
<MS ACCESS MVP>




scubadiver said:
That is what the code was originally and I still get the same error. Is
there an alternative?




Ken Snell (MVP) said:
Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




I have posted twice in the "import/export" forum and Mr Steele has given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
S

scubadiver

Thanks for the reply,

Ken has pointed out I may have made a couple of mistakes with my
referencing. I will check on Tuesday.




Tom Wickerath said:
Hi Scuba,

I'm a bit confused by your reference to the third line, since you've only
shown one line of VBA code. The space underscore ( _) line continuation
characters mean that this is all one line of code. A couple of suggestions:

1.) Declare string variables and assign the appropriate values. Use
Debug.Print statements to verify that the results look reasonable. For
example:

Dim strFileName As String
Dim strSavePath As String
Dim strFullPath As String

strFileName = [Forms]![menu]![Reports menu].Forms![SavePath]
strSavePath = "S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\" _
& "Queries Database 2007\New Database\"
strFullPath = strSavePath & strFileName & "\.xls"

Debug.Print "FileName: " & strFileName
Debug.Print "Path: " & strSavePath
Debug.Print "FullPath: " & strFullPath

Using a test spreadsheet saved in the intended path, with a pre-determined
name, you should be able to copy the FullPath from the Immediate Window,
paste it into the search box for finding Files or Folders, and locate this
file successfully.

2.) Use your new variable in the DoCmd.TransferSpreadsheet line:

DoCmd.TransferSpreadsheet TransferType:=acExport, _
TableName:="Report_Errors", FileName:=strFullPath, _
HasFieldNames:=True

Note: The "Errors" at the end of your line of code seems to correspond to
the optional UseOA argument, which I'm not sure has any real use.

3.) Verify that you have included the two very important words "Option
Explicit" as the second line of code at the top of your module:

Option Compare Database
Option Explicit

For more information on this, please see the following link:

Always Use Option Explicit
http://www.access.qbuilt.com/html/gem_tips.html#VBEOptions

4.) Verify that your code compiles without any errors. With any code module
open, click on:
Debug > Compile ProjectName

where ProjectName is the name of your VBA project.

5.) I recommend substituting the Uniform Naming Convention (UNC) path, in
place of the hard-coded drive letter "S:". That way, your code will not be
dependent on each user having the S drive correctly mapped.


Tom Wickerath
Microsoft Access MVP
https://mvp.support.microsoft.com/profile/Tom
http://www.access.qbuilt.com/html/expert_contributors.html
__________________________________________

:

I have posted twice in the "import/export" forum and Mr Steele has given me a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
P

(PeteCresswell)

Per scubadiver:
I want to let the user specify the file name before exporting.

How about popping a Common File dialog and having them navigate
to it?

Definitely not trivial the first time around, but once you get it
wired it will be a valuable addition to your repertoire.
 
S

scubadiver

Do tell !!!

I can create the save dialog box from the code in MVPS but not sure how to
relate it to the data I want to export.
 
S

scubadiver

Thanks for that. I seem to have got a little bit closer. It seems my
referencing has worked but I now have a date/time error problem. The field in
the query (which I am setting the criteria against) and the unbound text
boxes in the reports menu both have the following format:

dd/mm/yy

Yet I am getting an error mesage:

"An expression you entered is the wrong data type for one of the arguments".

The third argument is the text box to specify the file name.



Ken Snell (MVP) said:
You have an improper reference to the subform's control (you're using Forms
and it should be Form):

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , , "Errors"

Also, be sure that "Reports menu" is the name of the subform control that
actually holds the subform.

--

Ken Snell
<MS ACCESS MVP>




scubadiver said:
That is what the code was originally and I still get the same error. Is
there an alternative?




Ken Snell (MVP) said:
Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




I have posted twice in the "import/export" forum and Mr Steele has given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
K

Ken Snell \(MVP\)

You cannot use / character within a path or filename, and your code appears
to be concatenating the m/d/y format of the date into the path/file name
with the / character.

You have too many arguments in the TransferSpreadsheet call, by the way, as
well -- I missed that previously:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , "Errors"


--

Ken Snell
<MS ACCESS MVP>


scubadiver said:
Thanks for that. I seem to have got a little bit closer. It seems my
referencing has worked but I now have a date/time error problem. The field
in
the query (which I am setting the criteria against) and the unbound text
boxes in the reports menu both have the following format:

dd/mm/yy

Yet I am getting an error mesage:

"An expression you entered is the wrong data type for one of the
arguments".

The third argument is the text box to specify the file name.



Ken Snell (MVP) said:
You have an improper reference to the subform's control (you're using
Forms
and it should be Form):

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , , "Errors"

Also, be sure that "Reports menu" is the name of the subform control that
actually holds the subform.

--

Ken Snell
<MS ACCESS MVP>




scubadiver said:
That is what the code was originally and I still get the same error. Is
there an alternative?




:

Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




I have posted twice in the "import/export" forum and Mr Steele has
given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries
Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath]
&
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
S

scubadiver

I'm only using the dates to filter the records so I can't see why it should
affect the code. The "savepath" field is just text.



Ken Snell (MVP) said:
You cannot use / character within a path or filename, and your code appears
to be concatenating the m/d/y format of the date into the path/file name
with the / character.

You have too many arguments in the TransferSpreadsheet call, by the way, as
well -- I missed that previously:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , "Errors"


--

Ken Snell
<MS ACCESS MVP>


scubadiver said:
Thanks for that. I seem to have got a little bit closer. It seems my
referencing has worked but I now have a date/time error problem. The field
in
the query (which I am setting the criteria against) and the unbound text
boxes in the reports menu both have the following format:

dd/mm/yy

Yet I am getting an error mesage:

"An expression you entered is the wrong data type for one of the
arguments".

The third argument is the text box to specify the file name.



Ken Snell (MVP) said:
You have an improper reference to the subform's control (you're using
Forms
and it should be Form):

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , , "Errors"

Also, be sure that "Reports menu" is the name of the subform control that
actually holds the subform.

--

Ken Snell
<MS ACCESS MVP>





That is what the code was originally and I still get the same error. Is
there an alternative?




:

Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




I have posted twice in the "import/export" forum and Mr Steele has
given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries
Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath]
&
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
S

scubadiver

I now have another error:

cannot update. Database or object is read-only.

If I guess from other posts that this is because it can't deal with "XLS"
then I may need a rethink.



Ken Snell (MVP) said:
You cannot use / character within a path or filename, and your code appears
to be concatenating the m/d/y format of the date into the path/file name
with the / character.

You have too many arguments in the TransferSpreadsheet call, by the way, as
well -- I missed that previously:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , "Errors"


--

Ken Snell
<MS ACCESS MVP>


scubadiver said:
Thanks for that. I seem to have got a little bit closer. It seems my
referencing has worked but I now have a date/time error problem. The field
in
the query (which I am setting the criteria against) and the unbound text
boxes in the reports menu both have the following format:

dd/mm/yy

Yet I am getting an error mesage:

"An expression you entered is the wrong data type for one of the
arguments".

The third argument is the text box to specify the file name.



Ken Snell (MVP) said:
You have an improper reference to the subform's control (you're using
Forms
and it should be Form):

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Form![SavePath] &
".xls", , , "Errors"

Also, be sure that "Reports menu" is the name of the subform control that
actually holds the subform.

--

Ken Snell
<MS ACCESS MVP>





That is what the code was originally and I still get the same error. Is
there an alternative?




:

Get rid of the extra " characters:

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath] &
".xls", , , "Errors"

--

Ken Snell
<MS ACCESS MVP>




I have posted twice in the "import/export" forum and Mr Steele has
given
me
a
bit of help but I still get a "438" error on the third line

DoCmd.TransferSpreadsheet acExport, _
acSpreadsheetTypeExcel9, "Report_Errors", _
"""S:\ASSET DATA SERVICES\CUSTOMER SATISFACTION TEAM\Queries
Database
2007\New Database\" & [Forms]![menu]![Reports menu].Forms![SavePath]
&
".xls""", , , "Errors"

I want to let the user specify the file name before exporting.

Cheers
 
K

Ken Snell \(MVP\)

This new error likely is because the path and file name string for the file
is too long -- I believe the limit is 64 characters. Try shortening the
path/file name for the file in the fourth argument.
 
S

scubadiver

Thanks for your help. It is now working.



Ken Snell (MVP) said:
This new error likely is because the path and file name string for the file
is too long -- I believe the limit is 64 characters. Try shortening the
path/file name for the file in the fourth argument.
 

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