473,836 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to add sequential numbers to two recordsets

547 Contributor
Ok i am back with a question about recordsets.
I can add a record to two different recordsets at the sametime.(Racet imingT and RaceEntry5)

My problem: how do i add a sequential number to both recordsets and then copy data to different fields in these recordsets based on the sequential number.

It works 100% if i first add the data to a subform and then use beforeupdate to create sequential number and afterupdate to open recordset and copy it to different fields based on the sequential no. I would prefer to use recordsets for other technical issues - see code.
I use this code to copy data into the 2 recordsets and it works

Expand|Select|Wrap|Line Numbers
  1.  Dim varRet As Variant
  2.  Dim MyDB As DAO.Database
  4. 'Dim strSQL As String
  6.   Set MyDB = CurrentDb
  7.  Dim rst As DAO.Recordset
  8. Dim rst2 As DAO.Recordset
  9.  If IsNull(Me![strInput1]) Then Exit Sub
  11. 'strSQL = "SELECT * FROM RaceEntry5 WHERE [racetimingId] = " & Me![racetimingId]
  12.  'See if the Data has already been Captured, if not, Add, not Edit the Record
  14. 'If DCount("*", "Racetiming", "[racetimingId] = " & Me![racetimingId]) = 0 Then
  16.  Set rst = MyDB.OpenRecordset("RaceTimingT", dbOpenDynaset, dbAppendOnly)
  17. ' If DCount("*", "RaceEntry5", "[racetimingId] = " & Me![racetimingId]) = 0 Then
  19.  Set rst2 = MyDB.OpenRecordset("RaceEntry5", dbOpenDynaset, dbAppendOnly)
  21.  Dim strInputString As String        'Move with other Declarations
  22.  strInputString = Me![strInput1]
  23.  'See if Trailing Comma (,) is present, if so Extract it!
  24. If Right$(strInputString, 1) = "," Then
  25.    strInputString = Left$(strInputString, Len(strInputString) - 1)
  26. End If
  28.  varRet = Split(strInputString, ",")
  30.  Select Case UBound(varRet)      'How many Race Numbers?
  31.    Case 0        '1 Race#
  32.      With rst
  33.             .AddNew
  34.          'Must ADD the Child Linking Field
  35.          ![RaceNumber] = varRet(0)
  36.          ![RaceFinishTime] = Format(Now(), "General Date")
  37.          ![Racedate] = [Forms]![frmrtmainchip]![RacingDate]
  38.          '![RaceName] = [Forms]![frmrtmainchip]![RaceName]
  39.          '![RaceName] = DLookup("[RaceDetailID]", "RaceDetail", "[RaceName] = '" & Me.Parent![RaceName] & "'")
  40.        .update
  41.         End With
  42.     With rst2
  43.             .AddNew
  44.          'Must ADD the Child Linking Field
  45.          ![RaceNo] = varRet(0)
  46.          ![FinishTime] = Format(Now(), "General Date")
  47.          ![Racedate] = [Forms]![frmrtmainchip]![RacingDate]
  48.       '![RaceName] = [Forms]![racesetupxcf]![RaceName]
  49.        .update
  50.         End With
  51.  Case Else     'Who knows
  52.         'Me.strInput.SetFocus
  53.      'Do Nothing
  54.  End Select
  55.  rst.close
  56.  rst2.close
  57.  Set rst = Nothing
  58.  Set rst2 = Nothing
The current code in my subform to add the sequential numbers to the RacetimingT that must be incorporated into the above.
Expand|Select|Wrap|Line Numbers
  1. Dim lngLastLapNo As Long
  3.     lngLastLapNo = Nz(DMax("[LapNo]", "RaceTimingT", "[RaceNumber] = " & Me![RaceNumber] & _
  4. " AND [RaceName] = '" & Me.Parent![RaceName] & "'"), 0)
  5.    If lngLastLapNo = 0 Then    'Must be a new Race Number, so Reset Lap Number to 1
  6.   Me![LapNo] = 1
  7.   Else
  8.    Me![LapNo] = lngLastLapNo + 1
  9.      End If
The current code in my subform is used to copy data to the RaceEntry5 recordset
Expand|Select|Wrap|Line Numbers
  1.   Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim strSQL As String
  4.  Set MyDB = CurrentDb
  5. strSQL = "SELECT * FROM RaceEntry5 WHERE [racetimingId] = " & Me![racetimingId]
  6.  'See if the Data has already been Captured, if not, Add, not Edit the Record
  7. If DCount("*", "RaceEntry5", "[racetimingId] = " & Me![racetimingId]) = 0 Then     'NOT Captured/ADD
  8.   Set rst = MyDB.OpenRecordset("RaceEntry5", dbOpenDynaset, dbAppendOnly)
  9.   With rst
  10.  .AddNew
  11.  ![Racedate] = Me.Parent![RacingDate]
  12.  ![RaceNo] = Me![RaceNumber]
  13.  ![LapNo] = Me![LapNo]
  14.  ![Entries] = Me![FinishSeq]
  15.  ![lap10] = Me![RaceFinishTime]
  16.  ![racetimingId] = Me![racetimingId]
  17.  .Fields("Lap" & CStr(Me![LapNo])) = Me![RaceFinishTime]
  18.  ![RaceName] = DLookup("[RaceDetailID]", "RaceDetail", "[RaceName] = '" & Me.Parent![RaceName] & "'")
  19.   .update
  20.   End With
  21.   Else        'Data Captured, so Edit the Recordset
  22.   Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset)
  23.     With rst
  24.     .Edit
  25.   ![Racedate] = Me.Parent![RacingDate]
  26.  ![RaceNo] = Me![RaceNumber]
  27.  ![LapNo] = Me![LapNo]
  28.  ![Entries] = Me![FinishSeq]
  29.  ![lap10] = Me![RaceFinishTime]
  30.  ![racetimingId] = Me![racetimingId]
  31.  .Fields("Lap" & CStr(Me![LapNo])) = Me![RaceFinishTime]
  32.  ![RaceName] = DLookup("[RaceDetailID]", "RaceDetail", "[RaceName] = '" & Me.Parent![RaceName] & "'")
  33.    .update
  34.     End With
  35.    End If
  36.    rst.close
  37.    Set rst = Nothing
Anybody out there that can assist pls. I need to make these changes in order for one of the modules in my application to work with RFID. thx
Jan 5 '12 #1
21 3854
8,834 Recognized Expert Expert
I am very confused as to the exact nature of your Request, but I'll give it a stab. The following Code will add Sequential Numbers to 2 Recordsets ([Seq]) as well as adding a Unique Value to a Field in each each Recordset ([Result]) based on those Sequential Numbers.
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst1 As DAO.Recordset
  3. Dim rst2 As DAO.Recordset
  4. Dim lngSeqNum As Long
  6. Set MyDB = CurrentDb
  7. Set rst1 = MyDB.OpenRecordset("Table1", dbOpenDynaset)
  8. Set rst2 = MyDB.OpenRecordset("Table2", dbOpenDynaset)
  10. For lngSeqNum = 1 To 10
  11.   'ADD 10 Sequential Numbers to both Recordsets to the [Seq] Field. In
  12.   'the 1st Recordset, add 100 to the Sequential Number and store it in a
  13.   '[Result] Field. In the 2nd Recordset, square the Sequential Number and
  14.   'store it in a [Result] Field.
  15.   rst1.AddNew
  16.     rst1![Seq] = lngSeqNum
  17.     rst1![Result] = (lngSeqNum + 100)
  18.   rst1.Update
  20.   rst2.AddNew
  21.     rst2![Seq] = lngSeqNum
  22.     rst2![Result] = (lngSeqNum ^ 2)
  23.   rst2.Update
  24. Next
  26. rst1.Close
  27. rst2.Close
  28. Set rst1 = Nothing
  29. Set rst2 = Nothing
Jan 7 '12 #2
547 Contributor
Thx adezi. Sorry for complicating it like this.

To simplify it: In ie the racetimingT and RaceEntry5 tables (recordsets), the code must look individually at multiple fields in each of these tables and then add a sequential number to the LapNo field (number field) based on the current "racedate", and the "racenumber " fields (number field) in both.
Thus in this RacetimingT + RaceEntry5 tables, you will have many different racedates and racenumbers and lapno's from previous races.

What it must do - in the "Racetiming T" + RaceEntry5 recordsets it must look at the current "racedate" and current "racenumber " and the current "lapno" fields, and if the "lapno" = 0 or blank then it must add a "1" for this new racedate and racenumber when it gets added. If the lapno = "1" for these racedate and "racenumber " fields, then it must make it "2" etc etc
This same data will be added to both the RacetimingT and RaceEntry5 (tables) recordsets based on the criteria from previous records added.

to conclude:
RaceTimingT + RaceEntry5 tables = "RaceNumber " + "RaceDate"+ "LapNo" fields and the sequential number goes to the "Lapno" field.
Expand|Select|Wrap|Line Numbers
  1. Dim varRet As Variant
  2.  Dim MyDB As DAO.Database
  3.  Set MyDB = CurrentDb
  4.  Dim rst As DAO.Recordset
  5. Dim rst2 As DAO.Recordset
  6.   If IsNull(Me![strInput1]) Then Exit Sub
  8.   Set rst = MyDB.OpenRecordset("RaceTimingT", dbOpenDynaset, dbAppendOnly)
  9.   Set rst2 = MyDB.OpenRecordset("RaceEntry5", dbOpenDynaset, dbAppendOnly)
  10. Select Case UBound(varRet)      'How many Race Numbers?
  11.    Case 0        '1 Race#
  12.      With rst
  13.           .AddNew
  14.          'Must ADD the Child Linking Field
  15.          ![RaceNumber] = varRet(0)
  16.          ![RaceFinishTime] = Format(Now(), "General Date")
  17.          ![Racedate] = [Forms]![frmrtmainchip]![RacingDate]
  18.          ???? if racenumber and racedate exist for Lapno = 0, then add 1 to it etc etc (can go up to infinity)
  19.        .update
  20.         End With
  21.     With rst2
  22.             .AddNew
  23.          'Must ADD the Child Linking Field
  24.          ![RaceNo] = varRet(0)
  25.          ![FinishTime] = Format(Now(), "General Date")
  26.          ![Racedate] = [Forms]![frmrtmainchip]![RacingDate]
  27. ???? if racenumber and racedate exist for Lapno = 0, then add 1 to it etc etc (can go up to infinity)
  28.        .update
  29.         End With
  30.  Case Else     
  32.  End Select
  33.  rst.close
  34.  rst2.close
  35.  Set rst = Nothing
  36.  Set rst2 = Nothing

Hope it makes sense.
Jan 8 '12 #3
8,834 Recognized Expert Expert
  1. Is there a Linking Field between these 2 Tables? If so, what is it's name and Data Type?
  2. What exactly is the Relationship between these Tables?
Jan 8 '12 #4
547 Contributor
no its 2 separate tables with same fields but the data gets added to both.
RacetimingId is a unique ID field in RacetimingT table and "RaceEntry5 Id in the RaceEntry5 table when data gets added to it
Jan 8 '12 #5
547 Contributor
One can't perhaps add this also to the code for each of the tables
Expand|Select|Wrap|Line Numbers
  1. .Fields("Lap" & CStr(Me![LapNo])) = Me![RaceFinishTime]
This is to populate the racefinishtime of that specific lapno, to fields called either lapno1 or lapmo2 or lapno3 etc depending on the specific lapno involved in the racetimingT and RaceEntry5 tables
Jan 8 '12 #6
8,834 Recognized Expert Expert
Sorry neelsfer, but I am still at somewhat of a loss. At this point, I would need a condensed Version of the Database (2003) with a precise explanation of what needs to happen at a specific point.
Jan 8 '12 #7
547 Contributor
Thx adezi i will send one tonight South Africa time
Jan 9 '12 #8
547 Contributor
Hi Adezi
It must have been very confusing. Here is the DB. I have added instructions on the screens. thx for your time
Attached Files
File Type: zip timecopyissue2003.zip (198.5 KB, 113 views)
Jan 9 '12 #9
8,834 Recognized Expert Expert
Will.get.back.t o.you.
Jan 12 '12 #10

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

Similar topics

by: Jenn L | last post by:
I have a database that is pre-populated with sequential part numbers. As people reserve the parts I update a flag to show the # is no longer available. Now they want the ability to take out a block of "x" number of sequential part numbers - say for example 5. If my database had the following numbers available: 101 104 105 110
by: Ken | last post by:
This is a challenge. Perhaps someone can offer suggestions. I am trying to create a variable, ordernumber, that increases by an increment of 1 every time the variable is accessed. For example: Call up the variable the first time: ordernumber = 1 "Reopen" the webpage, call up the variable a second time: ordernumber = 2, etc.
by: Tony Williams | last post by:
I recently posted a message asking for help with sequential numbers. I want to create an autonnumber reference number that reverts back to 1 at the start of each year. GlenAppleton gave me some code and I thought I had it working but I don't. When I create a new record nothing happens in the control CommDocNbrtxt where the number should appear. Here is my complete code, can anyone help? If you read this Glen sorry to post again but I...
by: amywolfie | last post by:
Hi All: I know this is simple, but I just can't seem to get there: I need to sort a table by a text field (txtDescription), then assign sequential numbers to the field SEQUENCE in table. Every time a new record is added, the all SEQUENCE #'s must be reset. The re-numbering will be triggered by an EXPORT button.
by: Mike Kingscott | last post by:
Hi all, I'd building an app that posts to a web service. One of the things that is required in the soap header is a sequential number appended to a ref, i.e. "IGI1001", "IGI1002", etc. Obviously the first part of the reference ("IGI") stays the same, but I need an incrementing number generated. Now, I was thinking of doing this via a SQL database, but it would be an awful waste as there would only be one table and one stored procedure...
by: Bruce | last post by:
Surely someone has done this before, and I am guessing there is a simple solution that is eluding me. I have a simple report based on a recordset. For each record there is a field (RecNum) that is basically a sequential number from 1 to n. Occasionally there are skips between numbers. I would like to print 'record skipped' for each record missing from the sequence. For example, if there were no records numbered 5 and 6 in a sequence...
by: jtidwell | last post by:
I am developing a Work Order Database for my job. I have a combo box with "Contract Numbers" to select from. When you select on any Contract Number I need a new "Work Order Number" to appear. There are 10 different contract numbers so I need 10 different work order numbers (N10001, O100001, etc..) to generate sequential for each new record.
by: Finomosec | last post by:
Hi, i have a table of number-objects with beginning and endnr: 10-15 16-20 25-30 32-32 35-35 36-36 37-40
by: Excel 009 | last post by:
Hi, Is there a way to populate sequential numbers in a field using SQL or VBA? If yes, how? Assume the following is my existing table: Fruit ID Apply Banana
by: Joel Miller | last post by:
I found an article that was somewhat like what I was trying to do. The article was titled: SQL Query - Find block of sequential numbers Here is the article http://bytes.com/topic/sql-server/answers/81418-sql-query-find-block-sequential-numbers What I have is slightly different. I am trying to create a 'phone sheet' report which lists all the given phone numbers for a customer. Sometimes, the customer will have blocks of hundreds of...
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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,...
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...
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();...
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.