PDA

View Full Version : Runtime Error 2135



Giserno
11-05-2013, 10:58 AM
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?

SoftwareMatt
11-06-2013, 04:19 AM
What line does the error occur on?

Giserno
11-06-2013, 11:04 AM
What line does the error occur on?


Count = rsSQL.Fields("AnimalCount") + 1

Thats the line..

Thank you for responding Matt!

Cheers

SoftwareMatt
11-07-2013, 01:53 AM
Is that a type i.e. should Count be iCount?

Count = rsSQL.Fields("AnimalCount") + 1