+ Reply to Thread
Results 1 to 2 of 2

Help needed with Access Recordset

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-13-2004
    Posts
    120

    Help needed with Access Recordset in Excel

    Hey everyone,

    I can't seem to figure out what's not working here. I've put everything in, and it runs but for some reason, it's not pulling the correct number. When I run the code, it returns the last entry for the Survey_ID field. However, if I add a new record to the table and re-run it. It still returns the same one as last time. Anyone have any ideas on how to get it to pull the correct ID number?

    It's almost as if each time it's run, it's not clearing the recordset or requerying the db for an updated recordset.

    Public Sub getSurveyID()
    
        Dim rstTotal As New ADODB.Recordset
        Set rstTotal = Nothing
        Dim conTotal As New ADODB.Connection
        Set conTotal = Nothing
        Dim strCon As String
        Dim sPath As String
        Dim strTotal As String
        Dim intTotal As Integer
    
        
        ' Open connection
        sPath = ThisWorkbook.Path
         If Right$(sPath, 1) <> "\" Then sPath = sPath & "\"
        Set conTotal = New ADODB.Connection
        strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & sPath & "CARS.mdb;"
        conTotal.Open strCon
        
        Set rstTotal = New ADODB.Recordset
        rstTotal.CursorLocation = adUseClient
    
        strTotal = "Results"
        rstTotal.Open strTotal, conTotal, adOpenStatic, adLockReadOnly, adCmdTable
        
                    rstTotal.MoveLast
                    intTotal = rstTotal.Fields("Survey_ID")
                    MsgBox (intTotal)
    
        rstTotal.Close
        conTotal.Close
        Set rstTotal = Nothing
        Set conTotal = Nothing
    End Sub
    Last edited by dok112; 07-20-2007 at 05:49 PM.

  2. #2
    Forum Contributor
    Join Date
    06-13-2004
    Posts
    120
    Anyone have any thoughts on this? I could really use the help.

    TIA

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1