473,836 Members | 1,449 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
  3.  
  4. 'Dim strSQL As String
  5.  
  6.   Set MyDB = CurrentDb
  7.  Dim rst As DAO.Recordset
  8. Dim rst2 As DAO.Recordset
  9.  If IsNull(Me![strInput1]) Then Exit Sub
  10.  
  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
  13.  
  14. 'If DCount("*", "Racetiming", "[racetimingId] = " & Me![racetimingId]) = 0 Then
  15.  
  16.  Set rst = MyDB.OpenRecordset("RaceTimingT", dbOpenDynaset, dbAppendOnly)
  17. ' If DCount("*", "RaceEntry5", "[racetimingId] = " & Me![racetimingId]) = 0 Then
  18.  
  19.  Set rst2 = MyDB.OpenRecordset("RaceEntry5", dbOpenDynaset, dbAppendOnly)
  20.  
  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
  27.  
  28.  varRet = Split(strInputString, ",")
  29.  
  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
  2.  
  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
  10.  
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 3853
ADezii
8,834 Recognized Expert Expert
'Uncomment or Remove Code Line #33
Expand|Select|Wrap|Line Numbers
  1. '************************* Code Intentionally Removed *************************
  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
  13. 'Case Else     'Who knows
  14. 'End Select
  15. With rst2
  16.       .AddNew
  17.        ' ![RaceName] = Forms![FrmRTmainChip]![RaceName]
  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.  
  24.       .Update
  25.     End With
  26.  rst.Close
  27.  rst2.Close
  28.  Set rst = Nothing
  29.  Set rst2 = Nothing
  30.  
  31. Me.strinput1.Value = ""
  32.  
  33. 'Me.Requery
  34. [Forms]![FrmRTmainChip]![RaceTimingSF3chip].Requery
  35. [Forms]![FrmRTmainChip]![RaceEntry5sf].Requery
  36. '************************* Code Intentionally Removed *************************
Jan 16 '12 #21
neelsfer
547 Contributor
thx adezi for quick response. its sorted!
Jan 16 '12 #22

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

Similar topics

6
12713
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
2
2628
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.
2
3405
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...
14
12051
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.
2
1769
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...
4
2094
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...
6
6971
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.
3
5094
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
3
4698
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
18
2431
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...
0
9813
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
10831
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...
0
10536
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7778
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
6976
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();...
0
5815
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4005
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3108
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.