473,549 Members | 2,726 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Populate an Access 2000 Table with data from DAO Recordsets

8 New Member
Hello - Thanks for reading my post.

I am a newbie when it comes to VBA programming, but have managed to do what I need to do, until now.

I have an Access 2000 database (running WinXP Pro (SP3)).

I have successfully created 3 recordsets in my database. What I need to do is to take the data from those 3 recordsets and put them into a table so that I can run reports at a later time. I was able to create the recordsets and the table with all the fields that I need, but I do not know how to get the data from the recordsets into the table. Any assistance would be greatly appreciated.
Thank you

BeckR


Below is the code I am using.
Expand|Select|Wrap|Line Numbers
  1.     Dim dbs As DAO.Database
  2.     Dim regsrst As DAO.Recordset
  3.     Dim leaguerst  As DAO.Recordset
  4.     Dim teamrst As DAO.Recordset
  5.     Dim tfdnew As DAO.TableDef
  6.     Dim fldnew As DAO.Field
  7.     Dim ind  As DAO.Index
  8.     Dim strSQLL, strSQLT, strSQLR  As String
  9.     Dim intI As Integer
  10.  
  11.     strLeagueIdNo = Me!cmbChoose_League.Column(0)
  12.     strLeagueName = Me!cmbChoose_League.Column(1)
  13.  
  14.     Set dbs = CurrentDb()
  15.  
  16.     Debug.Print strLeagueIdNo   
  17.     Debug.Print strLeagueName   
  18.  
  19.     strSQLL = "SELECT * FROM Leagues " & _
  20.       "Where League_Id_No = " & strLeagueIdNo & ""
  21.       Debug.Print strSQLL
  22.     Set leaguerst = dbs.OpenRecordset(strSQLL)
  23.  
  24.     strSQLR = "SELECT * FROM Registrations " & _
  25.       "Where League_Id_No = " & strLeagueIdNo & ""
  26.       Debug.Print strSQLR
  27.       Set regsrst = dbs.OpenRecordset(strSQLR)
  28.       regsrst.MoveLast
  29.       NoTeams = regsrst.RecordCount
  30.       regsrst.MoveFirst    
  31.     strSQLT = "SELECT * FROM Teams " & _
  32.       "Where Team_Id_No = " & TeamId & ""
  33.       Debug.Print strSQLT
  34.     Set teamrst = dbs.OpenRecordset(strSQLT)
  35.  
  36.     TeamName = teamrst("Team_Name").Value
  37.     HeadCoach = teamrst("Head_Coach").Value
  38.     Address = teamrst("Address").Value
  39.     City = teamrst("City").Value
  40.     State = teamrst("State").Value
  41.     Zip = teamrst("Zip").Value
  42.     HomePhone = teamrst("Home_Phone").Value
  43.     WorkPhone = teamrst("Work_Phone").Value
  44.     CellPhone = teamrst("Cell_Phone").Value
  45.  
  46.     DoCmd.DeleteObject acTable, "League_Schedules"
  47.  
  48.     Set tfdnew = dbs.CreateTableDef("League_Schedules")
  49.  
  50.     Set ind = tfdnew.CreateIndex("PrimaryKey")
  51.  
  52.     With ind
  53.         .Fields.Append .CreateField("Receipt_No")
  54.         .Unique = False
  55.         .Primary = True
  56.     End With
  57.  
  58.      ' Append the new TableDef object to the Athletics Database
  59.     tfdnew.Indexes.Append ind
  60.  
  61.    With tfdnew
  62.       ' The CreateField method will set a default Size
  63.       ' for a new Field object if one is not specified.
  64.       .Fields.Append .CreateField("Receipt_No", dbInteger)
  65.       .Fields.Append .CreateField("ASA_No", dbText)
  66.       .Fields.Append .CreateField("League_Id_No", dbInteger)
  67.       .Fields.Append .CreateField("League_Name", dbText)
  68.       .Fields.Append .CreateField("No_Days", dbInteger)
  69.       .Fields.Append .CreateField("No_Games", dbInteger)
  70.       .Fields.Append .CreateField("Game_Type", dbInteger)
  71.       .Fields.Append .CreateField("Season_Start_Date", dbInteger)
  72.       .Fields.Append .CreateField("Age_Type", dbInteger)
  73.       .Fields.Append .CreateField("Day1", dbInteger)
  74.       .Fields.Append .CreateField("Day2", dbInteger)
  75.       .Fields.Append .CreateField("Day3", dbInteger)
  76.       .Fields.Append .CreateField("Time1", dbInteger)
  77.       .Fields.Append .CreateField("Time2", dbInteger)
  78.       .Fields.Append .CreateField("Time3", dbInteger)
  79.       .Fields.Append .CreateField("Time4", dbInteger)
  80.       .Fields.Append .CreateField("Time5", dbInteger)
  81.       .Fields.Append .CreateField("Location_1", dbInteger)
  82.       .Fields.Append .CreateField("Location_2", dbInteger)
  83.       .Fields.Append .CreateField("Location_3", dbInteger)
  84.       .Fields.Append .CreateField("Location_4", dbInteger)
  85.       .Fields.Append .CreateField("Location_5", dbInteger)
  86.       .Fields.Append .CreateField("Team_Name", dbInteger)
  87.       .Fields.Append .CreateField("Head_Coach", dbInteger)
  88.       .Fields.Append .CreateField("Address", dbInteger)
  89.       .Fields.Append .CreateField("City", dbInteger)
  90.       .Fields.Append .CreateField("State", dbInteger)
  91.       .Fields.Append .CreateField("Zip", dbInteger)
  92.       .Fields.Append .CreateField("Home_Phone", dbInteger)
  93.       .Fields.Append .CreateField("Work_Phone", dbInteger)
  94.       .Fields.Append .CreateField("Cell_Phone", dbInteger)
  95.    End With
Sep 4 '08 #1
11 3112
NeoPa
32,564 Recognized Expert Moderator MVP
BeckR, what do you mean when you say you have data stored in 3 recordsets?

A recordset is a dynamic code entity that refers to something that returns data. It doesn't fit in this context. Normally I'd assume you're simply referring to tables, but you refer to a table separately so I doubt that's the explanation in this case.
Sep 5 '08 #2
BeckR
8 New Member
Neopa

My apologies for the confusion.

I have created 3 DAO Recordsets which return data from 3 tables in the database. I then create a new table which needs to contain the information from the 3 DAO Recordsets. I have the recordsets and the table created, but I am not sure how to place the data from the recordsets into the new table. Once the new table is created, it then generates League Schedules using the new table data.

Thanks Neopa


BeckR
Sep 6 '08 #3
NeoPa
32,564 Recognized Expert Moderator MVP
Still a bit of confusion here I'm afraid. Are all the four tables of the same format? I assume they must be as you don't mention it.

If so, do you want to append ALL the records from ALL the three original tables into the fourth?
Sep 6 '08 #4
BeckR
8 New Member
That's because I don't speak "VBA" very well. :-)

I have 5 tables in the database. There a 3 of them that I need to pull certain information from. The 3 main tables are "Leagues", "Registrations" , and "Teams". For example I need to pull the Coach's information: i.e. Name, address, city, state, zip from the Teams table. I need to pull the League information from Leagues table and with the Registrations, I need to pull all Registration records where the League Id No = a combo box value on a form. I then need to count how many Registration records have been pulled from the Registration table.

Once I have the data pulled from all 3 tables (into DAO Recordsets?)
I then want to be able to put that information into a New table called League_Schedule s. I will then generate reports from the newly created League_Schedule s table.

What I am having problems with, is how do I get the information from the recordsets into the new table League_Schedule s? Do I need to use the INSERT INTO with VALUES?

I hope this makes more sense.. :-)
Sep 8 '08 #5
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi BeckR. I hope you don't mind me asking for clarification here; why are you using VBA to do any of this?? It only makes sense to me if you have a front end which is entirely coded in Visual Basic or somesuch. If you have Access 2000 as a front end, why are you not creating the table the way most tables are created in Access - in table design view?

For your updates and inserts, the norm is again not to be doing these in code as such (unless you have a specific requirement that demands it) - Access queries (which are just variants of SQL under the design front-end) will do all the hard work for you.

I can't help asking if there is a reason for all the code? It is an extraordinary effort to write a one-off process to create a table, when it takes just a few minutes to do the same task in the table design view of Access itself.

-Stewart
Sep 8 '08 #6
NeoPa
32,564 Recognized Expert Moderator MVP
...Continuing on from Stewarts thought provoking questions, do you really want to create a new table or is a simple query more likely to be an appropriate method?

Let us know your thoughts on these.
Sep 8 '08 #7
BeckR
8 New Member
Hi

The reason I am using VBA is because of where and how I generate the league schedules. I have a combo box (that lists all Leagues) on a form for the user. They choose which league they wish to generate a schedule for, they then click the command button to generate the desired schedule. It is in this code (On-Click) of command button that I am trying to determine which schedule to run. In order to generate the correct schedule, I need to know the No_Days, No_Games, and No_Teams that are currently selected. The No_Teams is a count of the records found in the Registrations Table that match the League chosen in the combo box. This information will change every time a different League is chosen. For example, the selected league plays 2 days per week, 21 games per season, and there are 6 teams in this particular league. (There could be anywhere from 4 teams – 10 teams in a League). Based on the information obtained, I will run a report named: 06 Teams - 11 Games - 2 Days. I want to use the newly created League_Schedule s table to run each of the different schedule reports. Am I going about this incorrectly? If there is a better way to get the schedules generated, I am certainly open to any suggestions.

Thank you for your time…
Sep 9 '08 #8
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi BeckR, and thank you for your explanation. I am sure now that you are not abstracting your table designs sufficiently, as you are in effect building bespoke tables to reflect particular league circumstances instead of designing a set of tables adaptable enough to cover any number of matches and any number of days etc.

If you look at the field list for the new table you are creating in post 1 you will see several repeated groups - times, locations, and days jump out. That your table includes such repeated groups means it is not in what is known as First Normal Form, and it reflects a lack of abstraction in table design.

Each of the repeated groups should be taken out into a separate table. We have a good introductory article on Database Normalisation and Table Structures in our HowTo section which you may find helpful.

A league recording database should be able to cope with any number of teams playing any number of matches over a season of any defined length. It is up to the designer of the system to make sure it does, not by generating bespoke tables on the fly but in designing a structure of related tables able to cope with all the situations you would expect to find in a typical league. The design of the tables is generally a one-off task (barring modifications and enhancements). By getting the design right from the start you can concentrate on the user interface and facilities you provide for your users, instead of what must have taken a fair amount of effort to code the generation of a bespoke non-relational table in VBA.

By the way, once your tables are in place you can use Access queries to provide views of your data joined in whatever way is appropriate. It is the norm to use queries as the basis for reports, as you can prepare queries which 'stick back together' the groups separated out in a normalised table structure.

-Stewart
Sep 9 '08 #9
NeoPa
32,564 Recognized Expert Moderator MVP
I strongly recommend this advice.

However heavy the workload of doing this change of design may appear to you now, you will certainly be saving yourself work (AND HEADACHES) by so doing.
Sep 10 '08 #10

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

Similar topics

0
1331
by: olliver.mierau | last post by:
Hi, I have a Access 2000 database which store in some tables about 500.000 recordsets. As the performance is not very impressive I created a table in a MySQL database and connected via ODBC. If I try to transfer the data via Access Append-Query an error comes up with something like "not possible to go back > you want to cointinue?". After...
4
2538
by: Vikrant | last post by:
Hey friends Can someone please suggest that how many recordset can be opened simultaneously for a MS-Access 2000 Database.Does that make any difference if we use ODBC or some other way of connecting to the database.
24
2755
by: Bob Alston | last post by:
Most of my Access database implementations have been fairly small in terms of data volume and number of concurrent users. So far I haven't had performance issues to worry about. <knock on wood> But I am curious about what techniques those of you who have done higher volume access implementations use to ensure high performance of the...
13
4432
by: Greg Strong | last post by:
Hello All, Hello All, What are the ToDo's / Gotchas to convert an MDB Access 2K2 database to an Access Project (i.e. ADP) file for the front end using Microsoft SQL Server 2000 Desktop Engine (MSDE 2000) for the back end? Now for the background. I have a prototype MDB file that was built in Access 2K2, and compiled in Access 2K to...
1
2569
by: Johann Blake | last post by:
I am looking for a good solution on how to implement data access in an application so that there is a clean separation between the data access layer, the business layer and the GUI layer. I am looking for a robust solution for a major application. Almost every developer seems to come up with a completely different solution. While many of them...
12
2234
by: Cy | last post by:
Hello Fellow New Group Folks, Here's today's problem. I was called in to help convert an Access 97 database to Access 2000. 99% of all my Access Dev. work has occurred in 2000, so I know very little about 97, however, from everything I read, it sounded like a conversion from 97 to 2000 should go smoothly. Boy was I wrong. Here's what...
20
37854
by: TC | last post by:
I need an automated procedure to copy data from an Access table to a SQL Server table. Speed is important. What is the recommended technique? I can export the data from Access, copy it via FTP, then import it into SQL Server. I've tried that, and the speed is acceptable. It is an ugly solution, however, and I expect to find a better one --...
7
7337
by: rguarnieri | last post by:
Hi! I'm trying to create a query with a boolean expression like this: select (4 and 1) as Value from Table1 this query return always -1, but when I make the same calculation in visual basic, the value returned is 0. Can anyone tell me why the expression (4 and 1) return different value
6
2664
by: jsacrey | last post by:
Hello everybody, I've got a bit of a situation that I could use some guidance with if possible. I work for an auditing firm where my users audit electronic shipping data for customers to see if they've been overcharged for shipments by truck and rail carriers. 99.9% of the time, one of our auditors needs to see all data sent by a...
0
7451
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...
0
7720
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. ...
0
7960
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7475
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...
0
6048
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...
0
5089
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...
0
3501
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1944
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
0
766
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...

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.