A simple clause as criterion for the find method

  • Thread starter Thread starter giannis
  • Start date Start date
G

giannis

I need to write a clause for the criterion of the find method.
Suppose that :
Dim n , s , criterion, m as String
Dim myrecordset as Recordset

m = "John Brown"
n = Left (m , 4)
s = Right (m , 5)

i need find the first record with [Name]=n and [Surename]=s
How must write the criterion for the find method (: myrecordset.FindFirst
criterion )
Whether from the follow clouses is correct ? The first or the second ?

1) criterion = "[Name]=" & n & " AND " & "[Surename]=" & s

or the :

2) criterion = "[Name]=" & "'" & n & "'" & " AND " & "[Surename]=" & "'" & s
& "'"

???
 
giannis said:
I need to write a clause for the criterion of the find method.
Suppose that :
Dim n , s , criterion, m as String
Dim myrecordset as Recordset

m = "John Brown"
n = Left (m , 4)
s = Right (m , 5)

i need find the first record with [Name]=n and [Surename]=s
How must write the criterion for the find method (: myrecordset.FindFirst
criterion )
Whether from the follow clouses is correct ? The first or the second ?

1) criterion = "[Name]=" & n & " AND " & "[Surename]=" & s

or the :

2) criterion = "[Name]=" & "'" & n & "'" & " AND " & "[Surename]=" & "'" & s
& "'"

If you tried them both you would have discovered that the second one works and the
first one doesn't in less time than it took to post your question.

BTW, "Name" is a bad name for a field or control as most objects in Access have a
property with the same name. It's easy for this to cause problems. Why not use
FirstName?
 
Back
Top