473,663 Members | 2,903 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a looping macro that will generate multiple tables

2 New Member
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 1497
twinnyfo
3,653 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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
38630
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 correctly assigned to specific person from another table? Thanks.
1
11572
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 is the problem listbox.DataSource = myds.Tables.DefaultView; // Here again listbox.DataTextField = "invid"; // Here again listbox.DataBind(); mycon.Close()
8
10389
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 together. To make data entry easier I would like to combine selected columns from the four tables onto a single dataview that could be used as the datasource for a datagrid control. The distinct updates, insert ans delete
13
6774
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 key points such as the store number and the store ID. The fields of those tables are generic fields such as sales per day, bank deposit and what not. The first field for each store table is the date and I've set that as the primary key as one...
4
8864
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 the tables together with various queries using a unique id. My task is to generate reports from these tables dynamically. The user will select the data they want to see and the script will export a spreadsheet containing this data. I've got the...
12
4129
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 when it is run.therefore not a exactly a multiple filter but a filter on one table where all the data is temporarily put when the filter is run. this filter would auto matically run whenever the databased is open presumably by using and autoexecute...
4
2214
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 to dynamically create tables through code based on parameters in existing tables. I will try to keep this short and to the point The goal is to extract values from existing tables I will give an example of two tables to keep it simple
2
3087
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 part, I still need help. Here's a quick question that can help me get rolling with a new project. I have multiple tables, all have the same field names and formats...what is the quickest way to merge them all into one large table? I've been doing...
6
6730
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 salesperson1 data through salespersonN with just salespersonN's data. The resultant tables would be named something like salesperson1 table1 through salespersonN table1 Make sense?
0
8436
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8345
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8858
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8548
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7371
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5657
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1757
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.