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

Advanced DAO recordset operations: Move records to another table

3
Hello all,

Here is what I need to do and need help with:
I have a table that is feeding a chart in a report in Access. If this table has more than 50 records, the graph gets messy, and this is where I need help with my solution to this. If the table has more than 50 records, I want to take the next 50 records after the 50th and move these to another table (which I need to create), and this will continue until there are no more records.

I have successfully setup a DAO recordset and can get the count of records, but need to know how I can interact with the recordset to accomplish what I'm trying to do (move records to another table based on their position in the recordset).

Any help will be greatly appreciated.
Thanks!
Jul 29 '08 #1
5 4266
trixb
3
Bump....anyone have any ideas?
Aug 1 '08 #2
Bump....anyone have any ideas?
Let's see if I can help. Assuming you have already done your record count to determine whether or not you will need to do this (probably be an If statement before this portion based on your RecordCount) you want to try the following:
Expand|Select|Wrap|Line Numbers
  1. Dim Counter as Integer
  2. Counter = 0
  3.  
  4. Do Until rst.EOF
  5.   rst.MoveNext  
  6.   Counter = Counter + 1
  7.   If Counter >50 then
  8.      ' Code to copy the files would go here 
  9.      ' Will probably be an AddNew and Edit depending on what you are working with
  10.      ' If you need me to lay this syntax out for you let me know
  11.   End If  
  12. Loop
Aug 1 '08 #3
trixb
3
Let's see if I can help. Assuming you have already done your record count to determine whether or not you will need to do this (probably be an If statement before this portion based on your RecordCount) you want to try the following:
Expand|Select|Wrap|Line Numbers
  1. Dim Counter as Integer
  2. Counter = 0
  3.  
  4. Do Until rst.EOF
  5.   rst.MoveNext  
  6.   Counter = Counter + 1
  7.   If Counter >50 then
  8.      ' Code to copy the files would go here 
  9.      ' Will probably be an AddNew and Edit depending on what you are working with
  10.      ' If you need me to lay this syntax out for you let me know
  11.   End If  
  12. Loop
Thank you so much for your reply. I had played around with my logic and actually came up with the exact structure as you proposed (rst.MoveNext until the counter reaches 50).
What I need help with, is the actual syntax after the counter has reached 50. How do I start moving these 50 records at a time to another table?

Again, your response is appreciated and I look forward to hearing what else you think.

Thanks,
TB.
Aug 1 '08 #4
ADezii
8,834 Expert 8TB
Bump....anyone have any ideas?
I made a Generic Template that should work quite well for you:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim MyRS As DAO.Recordset
  3. Dim MyRS_2 As DAO.Recordset
  4.  
  5. Set MyDB = CurrentDb()
  6.  
  7. Set MyRS = MyDB.OpenRecordset("<Table/Query/SQL Statement>", dbOpenDynaset)
  8. Set MyRS_2 = MyDB.OpenRecordset("<Table/Query/SQL Statement>", dbOpenDynaset)
  9.  
  10. 'Necessary for accurate Record Count
  11. MyRS.MoveLast: MyRS.MoveFirst
  12.  
  13. If MyRS.RecordCount > 50 Then
  14.   MyRS.Move 50      'Move to 51st Record
  15.   Do While Not MyRS.EOF
  16.     MyRS_2.AddNew       'Must Add prior to Deletion
  17.       MyRS_2![Field1] = MyRS![Field1]
  18.       MyRS_2![Field2] = MyRS![Field2]
  19.       MyRS_2![Field3] = MyRS![Field3]
  20.       '...
  21.     MyRS_2.Update
  22.     MyRS.Delete         'Now you can Delete the Record
  23.     MyRS.MoveNext       'Advance to next Record
  24.   Loop
  25. Else
  26.   'do nothing, <= 50 Records
  27. End If
  28.  
  29. MyRS.Close
  30. MyRS_2.Close
  31. Set MyRS = Nothing
  32. Set MyRS_2 = Nothing
Aug 2 '08 #5
NeoPa
32,556 Expert Mod 16PB
Instead of moving records around between tables, have you considered running the charts off a query that limits the number of records returned to fifty (SELECT TOP 50 ...)?
Aug 5 '08 #6

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

Similar topics

8
by: Dima Protchenko | last post by:
Hi, guys. Please help if you know something about this. Error: ADODB.Recordset error '800a0e78' Operation is not allowed when the object is closed. line: if not rs.EOF then (from the code...
3
by: Tlm | last post by:
Hello All, I have a form (FrmA) with a subform (SubFrmB) embedded in it. SubFrmB also has a subform embedded in it (SubFrmC) The form's recordsource is based on a table (TblA). SubFrmB's...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
22
by: Gerry Abbott | last post by:
Hi all, I having some confusing effects with recordsets in a recent project. I created several recordsets, each set with the same number of records, and related with an index value. I create...
13
by: Jan | last post by:
Hi I have a database that I use to keep track of the sales promotions that we send to companies. I normally send a mailing based on a subset of the companies in the database (found using the...
7
by: tdr | last post by:
I need to compare table 1 to table 2 and if the row/recordset in table 1 is different from table 2, write the entire row/recordset from table 1 to table 3. I can read an entire row/recordset ...
2
kcdoell
by: kcdoell | last post by:
Hello I have a code where I want to delete the records that are found in my DAO recordset. I took a stab at this for the first time and got it to work but it is only delete one record at a time. If...
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
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...
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
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...
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...

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.