473,836 Members | 1,509 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
21 3854
547 Contributor
thx adezi i appreciate your time
Jan 12 '12 #11
8,834 Recognized Expert Expert
I do believe that I have arrived at a viable solution. Rather than post the partial Code Modifications, I'll simply Attach a Revised Database, and we'll take it from there.
Attached Files
File Type: zip timecopyissue2003_Revised.zip (191.9 KB, 89 views)
Jan 13 '12 #12
547 Contributor
Thx Adezi you are spot on so far.
Is there anyway one can populate the following data to the lap1-10 fields in the RaceEntry5 table?
Expand|Select|Wrap|Line Numbers
  1. Rst2
  2. If Me.Lapno = "1" Then Me![Lap1] = Format(Now(), "General Date")
  3. etc etc
Jan 13 '12 #13
8,834 Recognized Expert Expert
Is there anyway one can populate the following data to the lap1-10 fields in the RaceEntry5 table?
I'll see what I can come up with, either later today, or this weekend.
Jan 14 '12 #14
8,834 Recognized Expert Expert
I think that Code Line #22 is what you are looking for:
Expand|Select|Wrap|Line Numbers
  1. '************************* Code Intentionally Omitted *************************
  2. 'Select Case UBound(varRet)      'How many Race Numbers?
  3.   'Case 0        '1 Race#
  4.     With rst
  5.       .AddNew
  6.         ![RaceName] = Forms![frmrtmainchip]![RaceName]
  7.         ![RaceNumber] = varRet(0)
  8.         ![RaceFinishTime] = Format(Now(), "General Date")
  9.         ![RaceDate] = [Forms]![frmrtmainchip]![RacingDate]
  10.         ![Lapno] = IIf(intLapNum = 0, 1, intLapNum + 1)
  11.       .Update
  12.     End With
  14.     With rst2
  15.       Select Case (intLapNum + 1)
  16.         Case 1 To 10        'Valid Lap Numbers
  17.           .AddNew
  18.             ![RaceNumber] = varRet(0)
  19.             ![RaceFinishTime] = Format(Now(), "General Date")
  20.             ![RaceDate] = [Forms]![frmrtmainchip]![RacingDate]
  21.             ![Lapno] = IIf(intLapNum = 0, 1, intLapNum + 1)
  22.             .Fields("Lap" & CStr(intLapNum + 1)) = Format(Now(), "General Date")
  23.           .Update
  24.         Case Else
  25.           'Don't know what you want to do here. Validation on the Lap Number
  26.           'should have previously been applied, before any Updates
  27.       End Select
  28.     End With
  29. 'Case Else     'Who knows
  30. 'End Select
  31. '************************* Code Intentionally Omitted *************************
Jan 14 '12 #15
547 Contributor
You are a legend Adezi! thx a million!!
Jan 15 '12 #16
8,834 Recognized Expert Expert
You are quite welcome, neelsfer.
Jan 15 '12 #17
547 Contributor
Hi Adezi - i have picked up a bug. If i have 2 dates in DB of different races, then it seems to move to the next date when i add a new racenumber. I attach DB
Attached Files
File Type: zip timecopyissue2003_date issue.zip (203.9 KB, 98 views)
Jan 15 '12 #18
8,834 Recognized Expert Expert
If i have 2 dates in DB of different races, then it seems to move to the next date when i add a new racenumber
Be more specific, I do not see this happening.
Jan 16 '12 #19
547 Contributor
As you press enter after adding a racenumber, it moves to the next date/race name. Go to 14/10/2011 and add a racenumber to see the problem.
I hope it is not just a A2007 problem
I attach data that i cleaned up in this DB
Attached Files
File Type: zip timecopyissue2003_date issue.zip (184.9 KB, 112 views)
Jan 16 '12 #20

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: 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...
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,...
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...
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...
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: 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.