Timtropolis
Registered User.
- Local time
- Today, 18:20
- Joined
- Jun 17, 2004
- Messages
- 84
Greetings,
I'm currently using .addnew and .edit methods to update a table in VBA.
I have a flag setup so that if a new id comes in , then I use the .Addnew method to add a record to my table.
Some of the records are update records, which need to have data pulled from certain fields, then updated into the record that was added. So I set up a routine that uses the .Edit to accomplish that.
However, I'm receiving "No current record" error when the code hits rst.edit.
I'm not sure why this is occuring and was wondering if someone could point me in the right direction.
I've included the code below to help.
TIA,
Tim
I'm currently using .addnew and .edit methods to update a table in VBA.
I have a flag setup so that if a new id comes in , then I use the .Addnew method to add a record to my table.
Some of the records are update records, which need to have data pulled from certain fields, then updated into the record that was added. So I set up a routine that uses the .Edit to accomplish that.
However, I'm receiving "No current record" error when the code hits rst.edit.
I'm not sure why this is occuring and was wondering if someone could point me in the right direction.
I've included the code below to help.
Code:
Do While Not rst.EOF
DayName = Format(rst!EarnedDate, "dddd")
If rst!EarnedDate <= rst3!StartDate And X = 0 Then
rst2.AddNew
rst2!SSN = rst!SSN
rst2!startofweekdate = rst3!StartDate - 7
rst2!weeknumber = rst3!week
Set db1 = CurrentDb()
Set tdf = db1.TableDefs("DSNYWorkingTable")
intNumFields = tdf.Fields.Count - 1
ReDim avarFields(intNumFields)
For Each fld In tdf.Fields
If DayName = fld.name Then
Select Case DayName
Case Is = "sunday"
rst2!SUNDAY = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
'rst2(" & dayname & ") = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "monday"
rst2!monday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "tuesday"
rst2!tuesday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "wednesday"
rst2!Wednesday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "thursday"
rst2!thursday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "friday"
rst2!friday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "saturday"
rst2!saturday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
End Select
Exit For
End If
Next fld
rst2.Update
rst.MoveNext
rst3.MoveFirst
X = 1
ElseIf rst!EarnedDate <= rst3!StartDate And X = 1 Then
rst2.Edit [B][COLOR="Red"]<--- Problem occuring here[/COLOR][/B]
Set db1 = CurrentDb()
Set tdf = db1.TableDefs("DSNYWorkingTable")
intNumFields = tdf.Fields.Count - 1
ReDim avarFields(intNumFields)
For Each fld In tdf.Fields
If DayName = fld.name Then
Select Case DayName
Case Is = "sunday"
rst2!SUNDAY = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
'rst2(" & dayname & ") = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "monday"
rst2!monday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "tuesday"
rst2!tuesday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "wednesday"
rst2!Wednesday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "thursday"
rst2!thursday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "friday"
rst2!friday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
Case Is = "saturday"
rst2!saturday = rst!SSN & " - " & rst!EarnedDate & " - " & rst!LeaveMins
End Select
Exit For
End If
Next fld
rst2.Update
rst.MoveNext
rst3.MoveFirst
If rst!EarnedDate > Dateholder Then
Dateholder = rst!EarnedDate
X = 0
End If
Else
rst3.MoveNext
End If
TIA,
Tim