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

How to split by the value of a field and copy to respectively excel files?

There is a table tbl1,with several fields, one of them is City, with the value varies from city1 to city30.
I want to use Access Marco to automatically using function transferspreadsheet to copy this tbl1 into 30 excel sheets, by the value of city. For eg, select * from tbl1 where city value=city1 , then put the selected records into excel file “\…\…\city1.xls”,
Thus generates 30 excel files.
Is there a simple way to achieve this, avoid writing 30 transferspreadsheets in a macro?
Thanks.
Twilight
Aug 1 '08 #1
4 1611
JM420A
8
I'm no pro, by any means, but I will throw this out there:

Look in to building code using Select Case or IF statements

Build a statement that looks for the city name and assign it to a variable

strCityName = rsCity.cityname

build your statement based off of that

Then you can have one long piece of code that checks the value of the city name. It may take longer to write, but it will work better.

I had a macro that ran like 10 open report functions, but it was printing blank forms, so I had to build code to check for null values, and if it was null, then it wouldn't print.

I'm not much help on the programmatic side, but I hope I gave you an idea of where else to start.

jm420a
Aug 1 '08 #2
As I am green hand, i cann't understand your meaning, can you give a much detailed explanation? for eg, which moudle are you using?
very very thanks.
Aug 4 '08 #3
NeoPa
32,556 Expert Mod 16PB
With a For loop in your code you can process through doing a TransferSpreadsheet of a query designed to SELECT only those records which match the current value (1 - 30).

With so little info provided I can be little more help I'm afraid.
Aug 7 '08 #4
ADezii
8,834 Expert 8TB
It ain't pretty, but it do work! (LOL).
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As DAO.QueryDef
  2. Dim intCounter As Integer
  3. Dim qdfDelete As DAO.QueryDef
  4.  
  5. 'Replace with your own Path to the *.xls Files
  6. Const strPathToXLS As String = "C:\Test\"
  7.  
  8. DoCmd.Hourglass True
  9.  
  10. 'Delete all 30 Querys temporarily created, should they already exist
  11. For Each qdfDelete In CurrentDb.QueryDefs
  12.   If Left$(qdfDelete.Name, 13) = "qryExportCity" Then
  13.     CurrentDb.QueryDefs.Delete qdfDelete.Name
  14.   End If
  15. Next
  16.  
  17. For intCounter = 1 To 30
  18.   Set qdf = CurrentDb.CreateQueryDef("qryExportCity" & CStr(intCounter), "Select * From tbl1 Where " & _
  19.                                      "[City] = 'City" & CStr(intCounter) & "';")
  20.   DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qryExportCity" & CStr(intCounter), strPathToXLS & _
  21.                                      "City" & CStr(intCounter) & ".xls", False
  22. Next
  23.  
  24. DoCmd.Hourglass False
P.S. - After running this code, you are now left with 30 Querys named qryExportCity1 thru qryExportCity30 consecutively as well as 30 Spreadsheets named City1.xls thru City30.xls in the strPathToXLS Path. To Delete the 'Querys', simply run code lines 11 through 15 again.
Aug 7 '08 #5

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

Similar topics

3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
5
by: Arjen | last post by:
Hi All, What I want to is using a string as PATTERN in a split function. This makes it possible for me to change the PATTERN on one place in my script... For example: $separator = ";"; $line...
7
by: matthew_carver | last post by:
Hello, I have an ASP page that loops through a SQL Server 2000 table, then downloads an Excel sheet the users can save, etc. Works fine, except, I see that in one particular "comments" field the...
2
by: Jen | last post by:
Trying to take one table in access and split it into multiple excel files(using an excel template); and then email based on email addresses in Table2; Of course, I would like to do all of this...
6
by: jjturon | last post by:
Can anyone help me?? I am trying to pass a Select Query variable to a table using Dlookup and return the value to same select query but to another field. Ex. SalesManID ...
9
by: CGW | last post by:
I asked the question yesterday, but know better how to ask it, today: I'm trying to use the File.Copy method to copy a file from a client to server (.Net web app under IIS ). It looks to me that...
5
by: Hokiecow | last post by:
I'm trying to import specific columns from an excel file (Requirements.xls) into an access table (tblRequirements). Using VBA, I'm able to import the entire excel file into table...
6
by: ivan.perak | last post by:
Hello, im a beginner in VB.NET... The thing i would like to do is as it follows.... I have a text file (list of names, every name to the next line) which is about 350000 lines long. I would...
3
by: Chuck | last post by:
I've been having problems with Access and Excel talking to one another. In the process of trying to add features (programs) to Access 97 I have lost the ability to export an Access query to an...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.