Consulting

Results 1 to 4 of 4

Thread: Runtime Error 2135

  1. #1
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    2
    Location

    Runtime Error 2135

    Hello Friends.
    I'm making a simple program that counts animals from a .txt file when a button is pushed, and then return them in a table. My problem is that i get a runtime error (2135) each time i push my button. Here is the code i use.

    Private Sub comCount_Click()    Dim sFileName As String
        Dim sAnimal As String
        Dim sQuery As String
        Dim dbs As DAO.Database
        Dim rsSQL As DAO.Recordset
        Dim iCount As Integer
    
    
        Set dbs = CurrentDb
    
    
        sFileName = "C:\Users\Giserno\Desktop\Animals.txt"
        Open sFileName For Input As #1
    
    
        While Not EOF(1)
            Line Input #1, sAnimal
            sQuery = "Select * from tblResults where AnimalName = """ & sAnimal & """"
            Set rsSQL = dbs.OpenRecordset(sQuery)
            If rsSQL.RecordCount = 0 Then
                rsSQL.AddNew
                    rsSQL.Fields("AnimalName") = sAnimal
                    rsSQL.Fields("AnimalCount") = 1
                rsSQL.Update
            Else
                rsSQL.Edit
                    Count = rsSQL.Fields("AnimalCount") + 1
                    rsSQL.Fields("AnimalCount") = iCount
                rsSQL.Update
            End If
            rsSQL.Close
        Wend
    
    
        Close #1
    
    
    End Sub
    The input in the .txt file looks like this:

    Dog
    Dog
    Dog
    Cat
    Cat
    Bird

    and when put in the table it should look like

    dog 3
    Cat 2
    Bird 1

    Does anyone know how i can fix this?

  2. #2
    VBAX Regular
    Joined
    Jun 2009
    Location
    Dorset
    Posts
    60
    Location
    What line does the error occur on?
    Regards
    JD
    ------------------------------------
    Software-Matters
    Dorset

  3. #3
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    2
    Location
    Quote Originally Posted by SoftwareMatt View Post
    What line does the error occur on?
    Count = rsSQL.Fields("AnimalCount") + 1
    Thats the line..

    Thank you for responding Matt!

    Cheers

  4. #4
    VBAX Regular
    Joined
    Jun 2009
    Location
    Dorset
    Posts
    60
    Location
    Is that a type i.e. should Count be iCount?

    Count = rsSQL.Fields("AnimalCount") + 1
    Regards
    JD
    ------------------------------------
    Software-Matters
    Dorset

Posting Permissions

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