Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Feb 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi all,
    I am attempting to use the FindFirst method on an indexed field (Sib) in a table located in a backend database using access 2007. Despite adhering to the syntax provided in online help, the code:

    rec.FindFirst "Sib = " & strGeno

    yields an error saying that the Access database engine does not recognise "the variable value" as a valid fieldname or expression

    whereas the code:

    rec.FindFirst rec!Sib = strGeno

    does not yield an error but does not find the record (which does exist!) either. Any suggestions as to how to make this go would be much appreciated!

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Is the field Sib a Text field? It sounds like it is as you are using strGeno.
    Change
    Code:
    rec.FindFirst "Sib = " & strGeno
    to

    Code:
    rec.FindFirst "Sib = " & chr(34) & strGeno & chr(34)
    Chr(34) is code for "". String values need to be surrounded by double quotes.
    Regards
    John



  3. #3
    New Lounger
    Join Date
    Feb 2004
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks John

    rec.FindFirst "Sib = " & "'" & strGeno & "'"

    fixes it

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts
    Quote Originally Posted by DustyOwl View Post
    rec.FindFirst "Sib = " & "'" & strGeno & "'"
    is exactly the same as
    rec.FindFirst "Sib = " & chr(34) & strGeno & chr(34)

    Once you get used to it, the chr(34) version is easier to read than "'", but either works.
    Regards
    John



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •