473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Access - TransferSpreadsheet Error

I have a form where the user picks a query to export and it should export to their desktop. The query is called "Staff_Export_Data".

Using the following VBA code. Getting the following Error: "Run-time error '424' object required" Here is my code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_export_File_Click()
  2.     Me.txtf.Value = environ("username")
  3.     Me.txte.Value = "Staff Export Data"
  4.     Me.txtp.Value = "C:\Users\" & Me.txtf.Value & "\" & "Desktop\" & Me.txte.Value & ".xlsx" 
  5.  
  6. DoCmd.TransferSpreadsheet acExport, *acSpreadsheetTypeExcel12Xml, "Staff_Export_Data", *me.txtp.value
  7. End Sub
Thank you for all your time and help,
David
Feb 27 '18 #1
7 1153
twinnyfo
3,653 Expert Mod 2GB
AirDavidADP,

I am assuming, the Me.txt[?] are Text Boxes? I would recommend simply using variables declared within the procedure, instead.

Additionally, in line 6 above:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.TransferSpreadsheet acExport, *acSpreadsheetTypeExcel12Xml, "Staff_Export_Data", *me.txtp.value
  2.  
Are the asterisks intentional? This could be your problem.

Hope this hepps!
Feb 27 '18 #2
Yes, this is code behind a form and I am using text boxes to find out which user and what they want to call the export.

Not sure why the asterisks are showing in the post, but they are not in my code.

I have different users and want to be able to save the query to each person desktop when they select the export button. If I hard code in the file path then it does save, but that means I am going to have to create a big if then statement to find out who is exporting the file.

Thank you for your help,
David
Feb 27 '18 #3
twinnyfo
3,653 Expert Mod 2GB
What values are coming up for txtf, txte and txtp?

You should not need to hard code either the filename or the path. Also, spaces in files names can sometimes wreak havoc with things, but, in this case, it shouldn't cause such an error.
Feb 27 '18 #4
Here are the values: txtf = wilsonr; txte = Staff Export Data; txtp = C:\Users\wilsonr\Desktop\Staff Export Data.xlsx

Let me go back and test with no spaces and see if I get the same error.

Thanks,
David
Feb 27 '18 #5
twinnyfo
3,653 Expert Mod 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmd_export_File_Click()
  2. On Error GoTo EH
  3.     Dim strUser     As String
  4.     Dim strXLName   As String
  5.     Dim strFileName As String
  6.  
  7.     Me.txtf.Value = environ("username")
  8.     Me.txte.Value = "Staff Export Data"
  9.     Me.txtp.Value = "C:\Users\" & Me.txtf.Value & _
  10.         "\Desktop\" & Me.txte.Value & ".xlsx"
  11.  
  12.     strUser = Me.txtf.Value
  13.     strXLName = Me.txte.Value
  14.     strFileName = Me.txtp.Value
  15.  
  16.     DoCmd.TransferSpreadsheet acExport, _ 
  17.         acSpreadsheetTypeExcel12Xml, _
  18.         "Staff_Export_Data", strFileName
  19.  
  20.     Exit Sub
  21. EH:
  22.     MsgBox "There was an Error!" & vbCrLf & vbCrLf & _
  23.         "Error Number: " & Err.Number & vbCrLf & _
  24.         "Description:  " & Err.Description
  25.     Exit Sub
  26. End Sub
Sometimes VBA does not like using references to objects in the actual function (it "shouldn't" affect things, but sometimes it does).
Feb 27 '18 #6
This works great. Thanks for the help. David
Feb 28 '18 #7
twinnyfo
3,653 Expert Mod 2GB
David,

Glad I could hepp!

Have a great day!
Feb 28 '18 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marcos | last post by:
Yesterday afternoon I lost access to my local MSDE 2000 sp3(a?) instance. Usinig NT or SQL authentication I get an 'access denied' error when I try to connect. This happened suddenly with no...
6
by: geronimo_me | last post by:
Hi, I am trying to run an Excel macro from an Access module, however when I run the code the macro runs but then I get an error in Access. The error is: Run-time error "440", Automation error. ...
4
by: RM | last post by:
Had VS .Net 2002 installed on W2k Server SP3 and supported a number of web sites. Installed VS .Net 2003 on Friday and now all web sites using .Net & MS ACCESS get this strange error upon open. ...
0
by: Gururaj Badam | last post by:
I get the following access denied error when i try to export an image Start of Error Message Access Denied. Description: An unhandled exception has occurred during the execution of the...
1
by: PK9 | last post by:
I am receiving the following error in Visual Studio 2003: "the web server reported the following error when attempting to create or open the web project HTTP/1.1 403 Access Forbidden" I am...
1
by: igotyourdotnet | last post by:
Ok, here is the issue: I have 2 web pages one does a file upload to a database and the other page does a FTP to a server, both pages use the c:\temp directory. The page that uploads to a database...
3
by: enough2Bdangerous | last post by:
access runtime error 3011 on docmd.openreport -------------------------------------------------------------------------------- Access database (file format 2002-2003) generates reports with...
6
by: suresh_nsnguys | last post by:
Hi, This is my first message to this forum.I am facing one problem in frames.when i am trying to access child frame from parent frame i am getting "Access Denied Error".i know the reason bcz i...
2
by: jthep | last post by:
I'm trying to get this piece of code I converted from C to work in C++ but I'm getting an access violation error. Problem occurs at line 61. Someone can help me with this? The function...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.