Results 1 to 20 of 20

Thread: [RESOLVED] RecordCount return -1

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2009
    Posts
    21

    [RESOLVED] RecordCount return -1

    Hi all. Please take a look at code below. Just simple select the table but it return -1. What have to be fixed ? Please help...

    ### GLOBAL VARIABLE ###
    Code:
    Private db As ADODB.Connection
    Const DBNAME = "\DSDW2.mdb;"
    ### Sync Down BUTTON ###
    Code:
    Private Sub cmdSyncdown_Click()
    Dim ConnectionString As String
    ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & DBNAME
    
    Set db = New ADODB.Connection
    db.Open (ConnectionString)
    db.BeginTrans
    
    'CALL METHOD HERE THEN SET Success Flag
    Dim tmpQueryStr As String
    tmpQueryStr = "VALID SQL SELECT STATEMENT HERE"
    
    Dim result As Integer
    result = conn.Execute(tmpQueryStr).RecordCount '#### THIS LINE ... result = -1 ####
    
    If result > 0 Then
        tmpQueryStr = "MSACCESS TESTED SQL UPDATE STATEMENT HERE"
        ExecuteDB(tmpQueryStr)
    Else
        tmpQueryStr = "MSACCESS TESTED SQL INSERT STATEMENT HERE"
        ExecuteDB(tmpQueryStr)
    End If
    
    If Success Then
        db.CommitTrans
    Else
        db.RollbackTrans
    End If
    
    db.Close
    End Sub
    ### FUNCTION ###
    Code:
    Public Function ExecuteDB(ByVal QueryStr As String, ByRef db As ADODB.Connection) As ADODB.Recordset
        On Error GoTo ErrorHandling:
        Dim rs As New ADODB.Recordset
        Set rs = db.Execute(QueryStr)
        Set ExecuteDB = rs
        Exit Function
    ErrorHandling:
        MsgBox QueryStr
        Success = False
        Set ExecuteDB = Nothing
    End Function
    ### END OF CODES ###
    Last edited by ClOuD_Za; Oct 26th, 2009 at 02:21 PM. Reason: RENAME TOPIC TO RESOLVED

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width