Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2004, 10:19 PM
rjp rjp is offline
Registered User
 
Join Date: Aug 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL "Last" instruction returns wrong value

I used the SQL instruction below:

sql1 = SELECT LAST(FLDS_Idx) FROM EXT_Field_Src
sql2 = SELECT LAST(FLDD_Idx) FROM EXT_Field_Dst

Where Idx represents autonumber fields starting at 1 for the table EXT_Field_Src and 0 for the table EXT_Field_Dst. By opening an ADO recordset using the function at the bottom of the post.
I get the correct answer for sql1 -- 88 and incorrect answer for sq12 -- 0 (it should be 87). The only difference between the tables
that i can see is that the one that returns 0 also starts at 0. This may be a red herring...

Another important point is that when i use MAX instead of LAST it works.

If anyone knows of similar strange occurences or possible reasons for this plz let me know; otherwise MAX does the job.

Thanks




'Executes a complete sequence of sql code which returns a single integer
    Public Function SQL_execute_int(sql As String) As Integer
    Const C_FUNCTION = "SQL_execute"
    'MsgBox sql
    Dim condatabase As New ADODB.connection
    Dim rst As New ADODB.recordSet
    Set condatabase = CurrentProject.connection
    rst.ActiveConnection = condatabase
    Dim fieldname As String, value As Integer
    On Error GoTo ERR_SQL
        rst.Open sql, condatabase, adOpenKeyset, adLockOptimistic
        If rst.EOF = True Then
            Call ERR_raise(ERR_sql_exec, C_FUNCTION, "No integer was returned") 'No records were returned
        Else
            rst.MoveFirst
            fieldname = rst.fields(0).name
            If (rst.EOF = False) Then
                value = rst.fields(0).value
            End If
        End If

        rst.Close
        condatabase.Close
        Set condatabase = Nothing
        SQL_execute_int = value
    Exit Function
ERR_SQL:
    Call ERR_throw_auto(ERR_sql_exec, C_FUNCTION, "Error executing SQL ||| " & sql & " |||")
End Function








Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA - SQL query returns nothing from MySQL Calligra Access VBA 6 September 19th, 2007 04:10 PM
SQL Query returns error Raphasevilla Access VBA 2 February 22nd, 2006 08:30 AM
SQL result returns nothing, but empty == false? barddzen Pro JSP 1 August 9th, 2004 12:52 AM
ADO Paging - ASP returns wrong PageCoun spencer Classic ASP Databases 1 July 29th, 2004 06:15 AM
what is wrong with this sql.. face Classic ASP Databases 5 September 23rd, 2003 03:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.