Add value to field in recordset

  • Thread starter Thread starter Brad
  • Start date Start date
B

Brad

Thanks for reading my question.

I am opening a table as a recordset and want to add a
value to one of the fields in the recordset. I can get
to the record in the recordset, but can't apply the value.

I've tried changing the recordset type, but that doesn't
seem to work for me. I must be doing something wrong.

Here is my code,

Thanks,

Brad

TheStartDateFunction resolves to a date. The field that
I want to add the date to is set to Date/Time

Private Sub DefaultTaxDateInEffect_AfterUpdate()
Dim dbs As Database, rst As Recordset
Dim DefaultEndDate As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblDefaultTaxValues", ,
dbAppendOnly)

If Not rst.EOF Then
rst.MoveLast
rst.MovePrevious
rst![DefaultTaxDateExpired] = TheStartDateFunction
End If
End Sub
 
Brad,

The way you have it you are editing DefaultTaxDateExpired in the second to last
record. Is that what you want? If so, add Rst.Edit before your other Rst
statements and Rst.Update afte all your other Rst statements.
 
I am opening a table as a recordset and want to add a
value to one of the fields in the recordset. I can get
to the record in the recordset, but can't apply the value.

You need to use the Edit method to open the recordset for editing, and
then the Update event to apply the edits:

If Not rst.EOF Then
rst.MoveLast
rst.MovePrevious
rst.Edit
rst![DefaultTaxDateExpired] = TheStartDateFunction
rst.Update
End If
End Sub
 
Thanks so much for the help.

I put the rst.edit after the movelast and moveprevious,
then the equals statement, then the rst.update.

If I did rst.edit before moving to the desired record,
the code didn't work.

Brad
-----Original Message-----
Brad,

The way you have it you are editing
DefaultTaxDateExpired in the second to last
record. Is that what you want? If so, add Rst.Edit before your other Rst
statements and Rst.Update afte all your other Rst statements.

--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
(e-mail address removed)
www.pcdatasheet.com



Thanks for reading my question.

I am opening a table as a recordset and want to add a
value to one of the fields in the recordset. I can get
to the record in the recordset, but can't apply the value.

I've tried changing the recordset type, but that doesn't
seem to work for me. I must be doing something wrong.

Here is my code,

Thanks,

Brad

TheStartDateFunction resolves to a date. The field that
I want to add the date to is set to Date/Time

Private Sub DefaultTaxDateInEffect_AfterUpdate()
Dim dbs As Database, rst As Recordset
Dim DefaultEndDate As String
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblDefaultTaxValues", ,
dbAppendOnly)

If Not rst.EOF Then
rst.MoveLast
rst.MovePrevious
rst![DefaultTaxDateExpired] = TheStartDateFunction
End If
End Sub


.
 
Back
Top