CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2000
    Posts
    67

    Recordset Arrays & loops in VB

    I need help!!
    I have pasted my code below. My problem (if you look at the code) appears when i hit more then one record in my search, i get the error message: Either Bof or Eof are true, or the current record has been deleted, the operation requested by the application require a current record. 3021.
    When the search gives one record as result, everything is ok. Do you see any elementary errors in my code?

    Very thankful for all answers! I'll rate you!

    Option Explicit
    Dim PrintFile As String
    Sub Main()

    Dim rsAddresses As ADODB.Recordset
    Dim rsNames As ADODB.Recordset
    Dim paf As PafSearchR
    Dim fld As ADODB.Field
    Dim sData As String
    Dim sglStart As Single
    Dim DataArray() As String
    ReDim DataArray(1, 0) As String
    Dim NameArray() As String
    ReDim NameArray(1, 0) As String
    Dim Testfield
    Dim Testfield2

    Dim cmds() As String 'inparameters
    Dim I As Long 'Counters
    Dim C As Long
    Dim C1 As Long
    Dim X As Integer
    X = 0

    Dim Name As String
    Dim OrganisationName As String
    Dim POBoxNo As String
    Dim SubBuildingName As String
    Dim BuildingName As String
    Dim BuildingNo As String
    Dim SubThoroughfareName As String
    Dim ThoroughfareName As String
    Dim SubLocalityName As String
    Dim LocalityName As String
    Dim PostalTownName As String
    Dim CountyName As String
    Dim DeliveryPointSuffix As String
    Dim InwardPostCode As String
    Dim OutwardPostCode As String
    Dim FullPostCode As String

    cmds = Split(Command, " ", -1)
    For I = 0 To UBound(cmds)
    PrintFile = cmds(0)
    FullPostCode = cmds(1)
    BuildingNo = cmds(2)
    OrganisationName = cmds(3)
    ThoroughfareName = cmds(4)
    PostalTownName = cmds(5)
    CountyName = cmds(6)
    Name = cmds(7)
    'Debug.Print " Command "; i; " = "; cmds(i)
    Next I

    Set paf = CreateObject("nbPAFSearchR.PafSearchR")
    Set rsAddresses = paf.DoPafSearch(FullPostCode, BuildingNo, "", "", "", "", "", 80, True, 100, True)
    Open PrintFile For Append As #1 ' Open outputfile for append.

    Set rsNames = paf.GetNames
    sData = ""
    For Each fld In rsAddresses.Fields
    sData = sData & fld.Name & ", "
    DataArray(1, C) = fld.Value
    Print #1, DataArray(1, C); "|";
    ReDim Preserve DataArray(1, C + 1) As String
    C = C + 1
    Next

    If Not rsNames Is Nothing Then
    sData = ""
    For Each fld In rsNames.Fields
    sData = sData & fld.Name & ", "
    NameArray(0, C1) = fld.Name
    NameArray(1, C1) = fld.Value
    Print #1, NameArray(1, C1); "|";
    ReDim Preserve NameArray(1, C1 + 1) As String
    C1 = C1 + 1
    Next
    Print #1, ";"

    End If
    Close #1
    Close
    End Sub









  2. #2
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Recordset Arrays & loops in VB

    Hi,

    I don't know how the object ("nbPAFSearchR.PafSearchR") works. But from MSDN, I found some information:
    ========
    An attempt was made to update records by using Find or Seek to move the record pointer to the desired record. If the record is not found, EOF will be True. This error can also occur after a failed AddNew or Delete because there is no current record when these methods fail.
    ==========

    Regards,

    Michi

  3. #3
    Join Date
    Jun 2001
    Location
    Sri Lanka
    Posts
    272

    Re: Recordset Arrays & loops in VB

    Instead of using

    for Each fld In rsAddresses.Fields
    ' .........
    next



    try using

    Do while rsAddresses.EOF = false and rsAddresses.BOF = false
    ' .........
    rsAddresses.MoveNext
    next






    If u don't know how to Rate an answer, then Rate my answer to learn, If u know, then practice it

  4. #4
    Join Date
    Aug 2000
    Location
    England
    Posts
    185

    Re: Recordset Arrays & loops in VB

    Hello,

    You could try using:

    rsNames.moveLast
    rsNames.moveFirst

    Before you start trying to read the records as this will get a valid record count for the recordset.

    Andrew


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

Featured