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
The current code in my subform to add the sequential numbers to the RacetimingT that must be incorporated into the above.
The current code in my subform is used to copy data to the RaceEntry5 recordset
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
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
Code:
Dim varRet As Variant Dim MyDB As DAO.Database 'Dim strSQL As String Set MyDB = CurrentDb Dim rst As DAO.Recordset Dim rst2 As DAO.Recordset If IsNull(Me![strInput1]) Then Exit Sub 'strSQL = "SELECT * FROM RaceEntry5 WHERE [racetimingId] = " & Me![racetimingId] 'See if the Data has already been Captured, if not, Add, not Edit the Record 'If DCount("*", "Racetiming", "[racetimingId] = " & Me![racetimingId]) = 0 Then Set rst = MyDB.OpenRecordset("RaceTimingT", dbOpenDynaset, dbAppendOnly) ' If DCount("*", "RaceEntry5", "[racetimingId] = " & Me![racetimingId]) = 0 Then Set rst2 = MyDB.OpenRecordset("RaceEntry5", dbOpenDynaset, dbAppendOnly) Dim strInputString As String 'Move with other Declarations strInputString = Me![strInput1] 'See if Trailing Comma (,) is present, if so Extract it! If Right$(strInputString, 1) = "," Then strInputString = Left$(strInputString, Len(strInputString) - 1) End If varRet = Split(strInputString, ",") Select Case UBound(varRet) 'How many Race Numbers? Case 0 '1 Race# With rst .AddNew 'Must ADD the Child Linking Field ![RaceNumber] = varRet(0) ![RaceFinishTime] = Format(Now(), "General Date") ![Racedate] = [Forms]![frmrtmainchip]![RacingDate] '![RaceName] = [Forms]![frmrtmainchip]![RaceName] '![RaceName] = DLookup("[RaceDetailID]", "RaceDetail", "[RaceName] = '" & Me.Parent![RaceName] & "'") .update End With With rst2 .AddNew 'Must ADD the Child Linking Field ![RaceNo] = varRet(0) ![FinishTime] = Format(Now(), "General Date") ![Racedate] = [Forms]![frmrtmainchip]![RacingDate] '![RaceName] = [Forms]![racesetupxcf]![RaceName] .update End With Case Else 'Who knows 'Me.strInput.SetFocus 'Do Nothing End Select rst.close rst2.close Set rst = Nothing Set rst2 = Nothing
Code:
Dim lngLastLapNo As Long lngLastLapNo = Nz(DMax("[LapNo]", "RaceTimingT", "[RaceNumber] = " & Me![RaceNumber] & _ " AND [RaceName] = '" & Me.Parent![RaceName] & "'"), 0) If lngLastLapNo = 0 Then 'Must be a new Race Number, so Reset Lap Number to 1 Me![LapNo] = 1 Else Me![LapNo] = lngLastLapNo + 1 End If
Code:
Dim MyDB As DAO.Database Dim rst As DAO.Recordset Dim strSQL As String Set MyDB = CurrentDb strSQL = "SELECT * FROM RaceEntry5 WHERE [racetimingId] = " & Me![racetimingId] 'See if the Data has already been Captured, if not, Add, not Edit the Record If DCount("*", "RaceEntry5", "[racetimingId] = " & Me![racetimingId]) = 0 Then 'NOT Captured/ADD Set rst = MyDB.OpenRecordset("RaceEntry5", dbOpenDynaset, dbAppendOnly) With rst .AddNew ![Racedate] = Me.Parent![RacingDate] ![RaceNo] = Me![RaceNumber] ![LapNo] = Me![LapNo] ![Entries] = Me![FinishSeq] ![lap10] = Me![RaceFinishTime] ![racetimingId] = Me![racetimingId] .Fields("Lap" & CStr(Me![LapNo])) = Me![RaceFinishTime] ![RaceName] = DLookup("[RaceDetailID]", "RaceDetail", "[RaceName] = '" & Me.Parent![RaceName] & "'") .update End With Else 'Data Captured, so Edit the Recordset Set rst = MyDB.OpenRecordset(strSQL, dbOpenDynaset) With rst .Edit ![Racedate] = Me.Parent![RacingDate] ![RaceNo] = Me![RaceNumber] ![LapNo] = Me![LapNo] ![Entries] = Me![FinishSeq] ![lap10] = Me![RaceFinishTime] ![racetimingId] = Me![racetimingId] .Fields("Lap" & CStr(Me![LapNo])) = Me![RaceFinishTime] ![RaceName] = DLookup("[RaceDetailID]", "RaceDetail", "[RaceName] = '" & Me.Parent![RaceName] & "'") .update End With End If rst.close Set rst = Nothing
Comment