Like Opertor is not working in MS acces-Retun error code 3021 -eith EOF OR BOF is tru

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • learnaccess3
    New Member
    • Jan 2010
    • 7

    Like Opertor is not working in MS acces-Retun error code 3021 -eith EOF OR BOF is tru

    Dar team

    need u r help

    I am new to aceess . I am writign a query in access for finding the last name mathcing with criteria using Like operator.
    Code:
    selct a,b,c from Table1 where last  name like '*"&  Paramter value &"*'
    When in debug mode I can see teh in immediate window teh query and when i put this query in query window in access it is returning the
    data also which is very good

    but in Actual from where I am using a function
    Code:
    set rs = getlastname(LastName)--(Last name is the Paramet er in above query)
    The function is as follows

    Code:
    Function getlastname(lastnamyName As String) As ADODB.Recordset
        Dim rs As ADODB.Recordset
        Dim strsql As String
        Dim da As New DABase
    
        
        strsql = "SELECT *"
        strsql = strsql & " FROM tables1  "
        strsql = strsql & " WHERE (((lastname) like  ""*" & lastame & "*"")) ;"
       
        da.openConnection
        da.CommandText = strsql
        Set getlastname= da.openRecordset
        Set da = Nothing
    
    End Function

    after completion of this fun.. I agin come in my main form where this fn has een written
    Code:
    set rs = getlastname(LastName)-
    after htis line rs.recordcount showing me as zero ??? so that is te reason run time error 3021 is coming..

    Funny thing is if I remove liek operator it is wrking finme.

    Request u r help
    Last edited by Stewart Ross; Jan 29 '10, 04:44 PM. Reason: Please use the [code] tags provided.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    Hi, and Welcome to Bytes!

    If you have copied and pasted your function accurately then you have a mis-spelt variable name in your LIKE clause:

    Code:
    strsql = strsql & " WHERE (((lastname) like ""*" & lastame & "*"")) ;"
    should be

    Code:
    strsql = strsql & " WHERE (((lastname) like ""*" & lastname & "*"")) ;"
    If this is the case, it also means that you are not using the OPTION EXPLICIT directive at the top of your code in the VBA Editor. If you were, the editor would itself pick up that you have an undeclared variable (which is what it will treat your misnamed variable as), in turn allowing you to see and fix the error before it causes you difficulties.

    I may be wrong, as there are many, many spelling errors in your post and in the code (including the parameter name, which in your function is listed as lastnamyName). If you have copied in code by hand please don't - give us the actual code you are using, not a mis-spelt version of it. Saves a lot of our time!

    -Stewart

    Comment

    • learnaccess3
      New Member
      • Jan 2010
      • 7

      #3
      Originally posted by Stewart Ross Inverness
      Hi, and Welcome to Bytes!

      If you have copied and pasted your function accurately then you have a mis-spelt variable name in your LIKE clause:

      Code:
      strsql = strsql & " WHERE (((lastname) like ""*" & lastame & "*"")) ;"
      should be

      Code:
      strsql = strsql & " WHERE (((lastname) like ""*" & lastname & "*"")) ;"
      If this is the case, it also means that you are not using the OPTION EXPLICIT directive at the top of your code in the VBA Editor. If you were, the editor would itself pick up that you have an undeclared variable (which is what it will treat your misnamed variable as), in turn allowing you to see and fix the error before it causes you difficulties.

      I may be wrong, as there are many, many spelling errors in your post and in the code (including the parameter name, which in your function is listed as lastnamyName). If you have copied in code by hand please don't - give us the actual code you are using, not a mis-spelt version of it. Saves a lot of our time!

      -Stewart
      team,

      Sorry for mis-spelling, In the code it is right, now again I have searced on the net. For DAO we need to put * & for ADO we can use %.

      Now it is wokring. Thanks for u r help Stewart.

      Sorry for the inconvenince

      Regds
      Amogh

      Comment

      Working...