+ Reply to Thread
Results 1 to 2 of 2

Recordset keeps returning EOF and shouldn't be.

  1. #1
    BerkshireGuy
    Guest

    Recordset keeps returning EOF and shouldn't be.


    Hello everyone,

    The following code should grab policy number from cell B from the
    activeworksheet, then go through a recordset (that is a SQL table) to
    find that recordset.

    However, the following code is always returning EOF even though I am
    hardcoding a policy number that I know exists in the table.


    Here it is:

    Dim oConn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim wb As Workbook
    Dim ws As Worksheet

    Set wb = ActiveWorkbook
    Set ws = wb.ActiveSheet
    Set rng = Cells(Rows.Count, 1).End(xlUp)

    (connection properties changed for privacy)

    oConn = "Driver={SQL Server};" & _
    "Server=OurSQLServer;" & _
    "Database=OverDatabase;" & _
    "Uid=joesmoe;" & _
    "Pwd="

    oConn.Open

    'rst.Open "Select polnum, EntryDate From tblOurTable", oConn,
    adOpenStatic

    For i = rng.Row To 3 Step -1
    'strPolicyNumber = Cells(i, "B").Value


    strPolicyNumber = "Z9999858" <--- This policy number is there, but
    recordset returns EOF


    rst.Open "Select polnum, F_EntryDate From ipdSysUser.tblQueueLoc_NBPROD
    WHERE polnum = ' " & strPolicyNumber & "'", oConn, adOpenStatic


    If rst.EOF Then GoTo NextPolicy:
    Debug.Print rst("polnum")

    NextPolicy:
    rst.Close
    Next i

    Thanks,
    Brian


  2. #2
    Forum Contributor colofnature's Avatar
    Join Date
    05-11-2006
    Location
    -
    MS-Off Ver
    -
    Posts
    301
    After your "rst.Open..." command, try putting in the following:


    if rst.RecordCount = 0 Then
    GoTo NextPolicy
    Else
    rst.MoveLast
    rst.MoveLast
    End If


    The MoveLast causes the DB handler to populate the recordset, and the MoveFirst sets the first record as the current one.

+ 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