FindFirst command

mfaqueiroz

Registered User.
Local time
Yesterday, 22:22
Joined
Sep 30, 2015
Messages
125
Hei all :)
I'm using for the first time the command rst.FindFirst, but isn't giving the right output--is moving always to first row

Dim strCriteria as String
Dim rst as DAO.RECORDSET

Date = RST.Fields(1)
Date1= Mid(Date, 7, 4) & "-" & Mid(Date, 4, 2) & "-" & Mid(Date, 1, 2) & " " & TimeValue(Date)
Machine1 = rst.Fields(2)
Tag1= rst.Fields(4)

strCriteria = "[State] = 'OK' and [Date] > #" & Date1 & "# AND [Machine]= ' " &Machine1 & " ' and [Tag] = '" &Tag1 & "' "

rst.FindFirst (strCriteria)

id2 = rst.Fields(0)


Could you please help me?:)

Thank you!! :)
 
I would not use FindFirst in this case. Rather, I would use this . . .
Code:
"[State] = 'OK' and [Date] > #" & Date1 & "# AND [Machine]= ' " &Machine1 & " ' and [Tag] = '" &Tag1 & "' "
. . . as the WHERE clause of my SQL to open exactly the recordset I need.
 
Also
Code:
Date = RST.Fields(1)

Date is a reserved word so I'm amazed it doesn't throw a spanner in the works here as well.
 
Ditto the other comments on Date being a reserved word.

However, after presumably opening the recordset (code not included), you take the values of the first record eg Machine1 = rst.Fields(2)
then do a find.

Of course it will always find the first record.
 
your Date1 value should also be formatted in US style -

e.g.

... & format(Date1,"mm/dd/yyyy") & ....
 

Users who are viewing this thread

Back
Top Bottom