Heidestrand
Registered User.
- Local time
- Yesterday, 21:25
- Joined
- Apr 21, 2015
- Messages
- 73
Hello community,
I have an issue with a recordset that I'm trying to solve but I somehow struggle with it. Couple of weeks ago the user arnelgp helped me out with a similar problem but I have troubles applying his method to my "new" situation.
What I want to do is: I want to compare dates again. But this time I want that for the first order number in column "sapsys_SAPNr" that he finds in my recordset he should compare the the dates of that order number. If there is a difference he should update the column "calenderdate" with the date from column "angelegtam".
But he should not touch the rest, on the first entry for an order number.
Here is an example:
For the order number "6231801" I have 5 records. In this case he only should compare the first record. As you can see in column "angelegtam" is 06.10.2014 and in "calenderdate" is 07.10.2014. Now he should update this date with the one from "angelegtam". But not the rest, only the first record.
I have tried this so far:
.. but it is not working. I'm not really sure what is missing.
I hope you can help me with this, really appreciate it
I have an issue with a recordset that I'm trying to solve but I somehow struggle with it. Couple of weeks ago the user arnelgp helped me out with a similar problem but I have troubles applying his method to my "new" situation.
What I want to do is: I want to compare dates again. But this time I want that for the first order number in column "sapsys_SAPNr" that he finds in my recordset he should compare the the dates of that order number. If there is a difference he should update the column "calenderdate" with the date from column "angelegtam".
But he should not touch the rest, on the first entry for an order number.
Here is an example:

For the order number "6231801" I have 5 records. In this case he only should compare the first record. As you can see in column "angelegtam" is 06.10.2014 and in "calenderdate" is 07.10.2014. Now he should update this date with the one from "angelegtam". But not the rest, only the first record.
I have tried this so far:
Code:
Sub Date()
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim varAngelegtAm As Variant
Dim varKalendertag As Variant
'Get the database and Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("SELECT * FROM tblSAPSys Order By sapsys_calenderdate ASC", dbOpenDynaset", dbOpenDynaset)
With rst
If .RecordCount > 0 Then .MoveFirst
While Not .EOF
' save order number and material number to variable, we'll use 'em later
varAngelegtAm = ![sapsys_angelegtam]
varKalendertag = ![sapsys_calenderdate]
'Search for the first matching record
rst.FindFirst "[sapsys_SAPNr] And varAngelegtAm <> varKalendertag
'Check the result
If Not rst.NoMatch Then
.Edit
![sapsys_calenderdate] = ![sapsys_angelegtam])
.Update
.MoveNext
EndIf
Wend
End With
End Sub
I hope you can help me with this, really appreciate it
