473,396 Members | 2,151 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 create a looping macro that will generate multiple tables

2
I'm trying to generate multiple tables using a query based on the unique SiteID, I have 32 sites in total and I would like to generate a table for each site (which I eventually would like to export all together into a single excel workbook).

So currently the query I've set up looks like this:
SELECT [Updated ANPR Analysis Site ID].New_SiteID AS Site_ID, [Updated ANPR Analysis Site ID].Base_class AS Class, [Updated ANPR Analysis Site ID].Corrected_vrn AS RegNo, [Updated ANPR Analysis Site ID].Timestamp AS [Time] INTO Site17
FROM [Updated ANPR Analysis Site ID]
WHERE ((([Updated ANPR Analysis Site ID].New_SiteID)=17))
The variable bits are obviously the Site_ID. Help!
Jan 24 '18 #1
3 1485
twinnyfo
3,653 Expert Mod 2GB
nalbi,

Welcome to Bytes!

A few things:

First, when posting Code or SQL strings, please use the proper Code Tags in your formatting.

Second, I think you will want to use VBA instead of a macro to accomplish this.

Third, what have you tried to actually create these Tables on your own. We are glad to troubleshoot your problems, but we are not in the habit of creating solutions.

Fourth, as I read your post, I would recommend against creating separate Tables for each of your sites. You would be better off creating one table, with the Site ID as one of the Fields. This is simply better DB structure.

Obviously, based on what you provided, our understanding of your problem is a bit limited. However, we are glad to provide guidance along the way to move you toward a solution.

Hope this hepps!
Jan 24 '18 #2
nalbi
2
Hi twinny,

my knowledge of vba/macros is extremely limited, I've been browsing similar topics/questions asked here but couldn't find an answer that I thought fitting.

I've been creating those tables manually by running the query over and over and changing the criteria to suit the SiteId I'm after. Unfortunately I need separate tables for each site for an independent bit of comparative work in excel. I was hoping I can automate this process as much as possible, but I don't know where to start!
Jan 24 '18 #3
twinnyfo
3,653 Expert Mod 2GB
nalbi,

You can still (I believe) accomplish what you are trying to do using one Table.

Theoretically, your code would reflect the following processes:
  1. Identify the list of Site IDs
  2. Import the data for each Site ID into the Table

There is no need to create new tables each time you import data. If the Table structure remains in tact, this saves on creating, recreating and deleting tables, which is a process that easily and quickly creates bloated DBs which can crash easily.

To export each Site ID to a spreadsheet, the processes are similar:
  1. Identify the list of Site IDs
  2. Export the data for each Site ID into a spreadsheet

This is not your solution, but guidance as to how to approach this solution. This does require knowledge and understanding of VBA, but you will benefit from the advantages of learning about proper DB design and execution.
Jan 24 '18 #4

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

Similar topics

5
by: Sami | last post by:
I can create queries and reports based on info from one table. How do I create one using information from multiple tables. What do I need to make sure the information from one table will be...
1
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here...
8
by: Jason L James | last post by:
Hi all, does anyone know if I can create a dataview from multiple datatables. My dataset is constructed from four separate tables and then the relationships are added that link the tables...
13
by: ricky.agrawal | last post by:
I'm really not sure how to go about this in Access. What I've created is a table for each location. Those tables are identical in format but different in information. The tables are named after...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
12
daniel aristidou
by: daniel aristidou | last post by:
hi i was wondering if it is possible to filter multiple numbers of tables at the same time. the filter would be automatically applied ie. as in a query. However i want only one list to appear...
4
by: nanabuch | last post by:
Hello, I am new to this forum, and I am a newbit in Oracle, I do have a background in MS Access, VBA, SQL server development and some Oracle backend development work. I have been giving a task...
2
by: Haas C | last post by:
Hi all, I am a newbie who goes through tasks in apainfully slow and in an inefficient way in Access. I've been experimenting here and there and have figured out a few things, but for the most...
6
by: Michael D | last post by:
I want to create a different table for each sales person listed in a table. If I have salesperson1 through salespersonN listed in the table, I'd like to end up with a table for salesperson1 with just...
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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...

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.