sql query gives blank result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    sql query gives blank result

    Code:
    VHANDICAP = rs("HANDICAP")
    strSQL = "SELECT MAX(AMOUNT) FROM TABLE WHERE VHANDI= " & VHANDICAP & "'"
    Debug.Print strSQL
    rs.Open strSQL, CurrentProject.Connection, adOpenKeyset, adLockOptimistic
    sql query gives blank result for those employees who are not handicap
    kindly help me to correct the error
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    Line 3 gives a debug print.
    Please run your code,
    Presss <ctrl><g> to open the immediates window.
    Copy the resolved string from that window to a post here, please format that information using the [CODE/] button.
    (I suspect you're missing a quote mark)
    Also any errors you are receiving.

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      You have a closing single quote for your handicap value, but you don't have an opening single quote.

      Comment

      • kkshansid
        New Member
        • Oct 2008
        • 232

        #4
        sorry the query is
        Code:
        strSQL = "SELECT MAX(AMOUNT) FROM TABLE WHERE VHANDI= '" & VHANDICAP & "'"
        it dont give error but provide blank result null value got from recordset is not null in query
        Last edited by zmbd; Sep 10 '13, 12:02 PM. Reason: [Z{Please use the [CODE/] button to format posted code/html/sql - Please read the FAQ}]

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Then you'll need to follow zmbd's instructions to find the query that is running

          Comment

          • kkshansid
            New Member
            • Oct 2008
            • 232

            #6
            Code:
            Select max(amount) 
            from table 
            where vhandicap=''
            Code:
            select * 
            from table 
            where vhandicap=''
            both query gives blank record
            Last edited by zmbd; Sep 10 '13, 12:05 PM. Reason: [Z{Please use the [CODE/] button to format posted code/html/sql - Please read the FAQ}{stepped SQL}{fixed typo}]

            Comment

            • jimatqsi
              Moderator Top Contributor
              • Oct 2006
              • 1290

              #7
              kkshansid, have you tried pasting this sql string into the query editor in SQL view and running tests from there? You could easily modify your query and check results instantly. After you know what query gives the result you want then you could work on assembling that query in code.

              I'm wondering if the data is as you think it is. This simple test may open your eyes to something.

              Jim

              Comment

              • jimatqsi
                Moderator Top Contributor
                • Oct 2006
                • 1290

                #8
                As an aside, what is line 1 of the code in your first post about? It appears from that snippet of code that you are getting a value from a recordset that is not yet open.

                Jim
                Last edited by jimatqsi; Sep 10 '13, 10:49 AM. Reason: typo

                Comment

                Working...