473,385 Members | 1,927 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,385 software developers and data experts.

EXPORT AND DELETE from access to excel

Hi all,

I wish to find out how to export data to excel from access as follows:

Select date range (which i understand how to do)

The data from an entire table is sent to excel

the filename of that export is the date range i selected

I am asked where i wish to save the file

On success, the table data is deleted
May 12 '07 #1
6 2414
JConsulting
603 Expert 512MB
Hi all,

I wish to find out how to export data to excel from access as follows:

Select date range (which i understand how to do)

The data from an entire table is sent to excel

the filename of that export is the date range i selected

I am asked where i wish to save the file

On success, the table data is deleted
1) create a form with a textbox and a button.

the textbox will hold the path returned by the code that gets executed when the button is pressed.

this the button code

Expand|Select|Wrap|Line Numbers
  1. Dim strFolderName As String
  2. strFolderName = BrowseFolder("What Folder you want to select?")
  3. Me.mytextbox = strFolderName & "\"
  4.  
Paste this entire code into a CODE module. Name the module anything except the function name.

Expand|Select|Wrap|Line Numbers
  1. '************** Code Start **************
  2. 'This code was originally written by Terry Kreft.
  3. 'It is not to be altered or distributed,
  4. 'except as part of an application.
  5. 'You are free to use it in any application,
  6. 'provided the copyright notice is left unchanged.
  7. '
  8. 'Code courtesy of
  9. 'Terry Kreft
  10.  
  11. Private Type BROWSEINFO
  12.   hOwner As Long
  13.   pidlRoot As Long
  14.   pszDisplayName As String
  15.   lpszTitle As String
  16.   ulFlags As Long
  17.   lpfn As Long
  18.   lParam As Long
  19.   iImage As Long
  20. End Type
  21.  
  22. Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
  23.             "SHGetPathFromIDListA" (ByVal pidl As Long, _
  24.             ByVal pszPath As String) As Long
  25.  
  26. Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
  27.             "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
  28.             As Long
  29.  
  30. Private Const BIF_RETURNONLYFSDIRS = &H1
  31. Public Function BrowseFolder(szDialogTitle As String) As String
  32.   Dim X As Long, bi As BROWSEINFO, dwIList As Long
  33.   Dim szPath As String, wPos As Integer
  34.  
  35.     With bi
  36.         .hOwner = hWndAccessApp
  37.         .lpszTitle = szDialogTitle
  38.         .ulFlags = BIF_RETURNONLYFSDIRS
  39.     End With
  40.  
  41.     dwIList = SHBrowseForFolder(bi)
  42.     szPath = Space$(512)
  43.     X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
  44.  
  45.     If X Then
  46.         wPos = InStr(szPath, Chr(0))
  47.         BrowseFolder = Left$(szPath, wPos - 1)
  48.     Else
  49.         BrowseFolder = vbNullString
  50.     End If
  51. End Function
  52. '*********** Code End *****************
  53.  
Now when you press the button, a directory browser will open allowing your user to select the location they want for your file.

2)
Exporting an entire table

Expand|Select|Wrap|Line Numbers
  1. Dim myFileName As String
  2. myFileName = Me.mystartdate & "to" & Me.myenddate
  3. DoCmd.OutputTo acOutputTable, "yourtablename", acFormatXLS, myFileName, False
  4.  
That should about do it. Given that this all done on the same form. The last bit of code assumes that you have two textboxes on your form for start date and end date. the filename would look like 1/1/2007to1/31/2007
Enjoy!
J
May 12 '07 #2
JConsulting
603 Expert 512MB
Hi all,

I wish to find out how to export data to excel from access as follows:

Select date range (which i understand how to do)

The data from an entire table is sent to excel

the filename of that export is the date range i selected

I am asked where i wish to save the file

On success, the table data is deleted
one slight change...

this would go into the last code segment I sent replacing the line

Expand|Select|Wrap|Line Numbers
  1. myFileName = Me.mypathtextbox & Me.mystartdate & "to" & Me.myenddate
  2.  
Had to include the path that your user selected.
J
May 12 '07 #3
Brilliant. Where would i add that last piece of code?
May 13 '07 #4
sorry, can you explain where all the code should be put as it doesnt state
May 13 '07 #5
JConsulting
603 Expert 512MB
sorry, can you explain where all the code should be put as it doesnt state

Do you mean the last post? OR all of it?
May 13 '07 #6
just the bit after the large module code
May 14 '07 #7

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

Similar topics

11
by: Mike MacSween | last post by:
My client has an MS Access database application on her local machine. I have full access to that in terms of changing the design. I've got a simple PHP/MySql application on shared hosting, so no...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
1
by: Kevin Blakeley | last post by:
I know this was just posted but I did not want this message to get lost in the other thread as it's slightly different. Yes I want to export my dataset to excel for my clients, but I don't want...
6
by: jcf378 | last post by:
hello-- i am having trouble figuring out how to export individual records from an Access 2002 Form into a pre-existing Excel spreadsheet, such that the exported record is merely appended to the...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
3
by: yovation | last post by:
Hi, I have a 3 table database. 1 parent 1 child 1 child of child I would like to get the data into excel as 1 sheet (similar to a grouped report).
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
1
by: DennisBetten | last post by:
First of all, I need to give some credit to Mahesh Chand for providing me with an excellent basis to export data to excel. What does this code do: As the title says, this code is capable of...
2
hemantbasva
by: hemantbasva | last post by:
Note We need to have a template on server for generating report in multiple sheet as we do not had msoffice on server moreover this require a batch job to delete excel file created by the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.