.FIND whit criteria...right 5

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

.FIND whit criteria...right 5

Post by sal21 »

i use this code to find in recordset but not work, as usula:(

Code: Select all

RS1.MoveFirst
RS1.Find "RIGHT(MATRICOLA,5)='" & Right(CODICE_MATR, 5) & "'"
in effect in need to find in right 5 of field MATRICOLA...

User avatar
HansV
Administrator
Posts: 78548
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: .FIND whit criteria...right 5

Post by HansV »

You can't use a calculated expression as the first part of the argument to Find. It must be a field name.

You could create a query with a calculated column

Last5: Right(MATRICOLA,5)

You can then open a recordset on this query and use

Code: Select all

RS1.Find "Last5='" & Right(CODICE_MATR, 5) & "'"
If you use DAO instead of ADO, you can use FindFirst which does support expressions such as you're trying to use.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4364
Joined: 26 Apr 2010, 17:36

Re: .FIND whit criteria...right 5

Post by sal21 »

HansV wrote:You can't use a calculated expression as the first part of the argument to Find. It must be a field name.

You could create a query with a calculated column

Last5: Right(MATRICOLA,5)

You can then open a recordset on this query and use

Code: Select all

RS1.Find "Last5='" & Right(CODICE_MATR, 5) & "'"
If you use DAO instead of ADO, you can use FindFirst which does support expressions such as you're trying to use.
I just have post this question many time...
But to find value in field wath is the best way in order of speeding search:

-a sql select with wehre
-a .find statement
-a .filter statement
-a seek
or?

in my case a need to scanning a value in a field/column with 14.000 rows!

User avatar
HansV
Administrator
Posts: 78548
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: .FIND whit criteria...right 5

Post by HansV »

A query (SQL statement) that selects the records you want is the most efficient way.
Best wishes,
Hans