Either BOF or EOF is True or the current record has been deleted

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ronie9
    New Member
    • May 2014
    • 3

    Either BOF or EOF is True or the current record has been deleted

    I am trying to get specific data by entering a value in a TextBox.
    -----------------------------------------------------------
    Code:
    Sub GetData()
     blatt = ActiveSheet.Name
        zeile = 1
        spalte = 1
        q = "select * from customers where country='TextBox1.Text'"
       x = ODBCQueryDaten(q, blatt, zeile, spalte)
        Range("A2").Select
        
    End Sub
    
    * This is the code when i hit the command button i made, where i get the msg"Either Bof or Eof etc.."
    
    but if i change "TextBox1.Text" to a value like 'Germany' i would get the data correct.
    ------------------------------------------------------------
    
    This is the code where it takes me after getting the error , if needed: 
    
    Public Function ODBCQueryDaten(query As String, blatt As String, zeile As Long, spalte As Long) As Boolean
        Dim rs As ADODB.Recordset
        Dim smax As Long
        Dim s As Long
        Dim zmax As Long
        Dim z As Long
        Dim v As Variant
        Dim w As String
        
        
        'Datenbank verbinden
        ODBCConnect
        'Datensätze holen
        Set rs = New ADODB.Recordset
        rs.CursorLocation = adUseClient
        rs.Open query, Conn ', adOpenForwardOnly, adLockOptimistic
        'Spaltenzahl/Zeilenzahl
        smax = rs.Fields.Count
        'nix gefunden
        If rs.AbsolutePosition = -1 Then
            Worksheets(blatt).Cells(zeile, spalte) = "nix"
        Else
            rs.MoveLast
            zmax = rs.RecordCount
        End If
            'Spaltenüberschriften
            For s = 0 To smax - 1
                Worksheets(blatt).Cells(zeile, spalte + s) = rs.Fields(s).Name
            Next s
            zeile = zeile + 1
            'Zeilenwerte
            rs.MoveFirst
            For z = 0 To zmax - 1
                'Spaltenwerte
                For s = 0 To smax - 1
                    'Wert konvertieren
                    Set v = rs.Fields(s)
                    If IsNull(v) Then
                        w = "<NULL>"
                    ElseIf IsEmpty(v) Then
                        w = "<EMPTY>"
                    Else
                        w = Komma2Punkt1(v)
                    End If
                    'Wert in Zelle
                    Worksheets(blatt).Cells(zeile + z, spalte + s) = w
                Next s
                'nächster Datensatz
                rs.MoveNext
            Next z
    '    End If
        'Wert zurück
        ODBCQueryDaten = True
        'Datenbank schliessen
        ODBCClose
    End Function

    Thanks a lot , hope to get an answer soon
    Last edited by Rabbit; May 23 '14, 05:13 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    What program are you using? Part of the problem is that you are passing the literal text "Textbox1.T ext" instead of the value inside the textbox. This is why it works when you plug "Germany" into it. Since there is no country named "Textbox1.Text" , you won't get any records returned. You need to split the string out so that it can pull the value that is inside the textbox. Because of the Range("A2").Sel ect line, I'm going to guess you are using Excel, in which case I'm not sure the proper way to reference the value in a textbox, so I'll leave it the same as how you have it and just do the concatenation portion.
    Code:
    q = "select * from customers where country='" & TextBox1.Text & "'"

    Comment

    • Ronie9
      New Member
      • May 2014
      • 3

      #3
      Hello Seth , thanks a lot for the reply

      yes im using excel and trying to retrieve specific data from mysql databas by giving a value in the textbox. now when i did what you wrote me i got the error msg"run-time erorr 424, object required"

      I tried many things to get it work but still i cant get it to read the text from the textbox.

      regards

      Comment

      • Ronie9
        New Member
        • May 2014
        • 3

        #4
        thanks you very much , it works now fine

        little change was
        Code:
        q = "select * from customers where country='" & UserForm1.TextBox1.Text & "'"

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          Glad you got it to work.

          Comment

          Working...