Runtime Error 3061 (1 Viewer)

boblife42

Registered User.
Local time
Today, 02:15
Joined
May 30, 2008
Messages
32
Hello
I am comparing an array word to two different tables if the word is in one of the tables then I increase the count of that word, if the word is not in either table I add the word to a specific table. I thought I had the code figure out but I am getting a Runtime Error, any help would be appreciated.
The words have to be in uppercase to match the table.
Code:
Private Sub DescProblem_LostFocus()
Dim rs As Recordset
Dim rs1 As Recordset
Dim rs2 As Recordset
Dim strSQL As String
Dim mySQL As String
Dim strArray() As String
Dim UCaseWord As String
Dim x As Integer

'Split text into array from description problem textbox
strArray = Split(DescProblem)
For x = 0 To UBound(strArray)
'Change strArray to UPPERCASE
UCaseWord = UCase(strArray(x))
'Query tbl_IndexedWord_Not_Used
    strSQL = "SELECT * FROM tbl_IndexedWord_Not_Used WHERE tbl_IndexedWord_Not_Used = '" & UCaseWord & "'"
Set rs = CurrentDb.OpenRecordset(strSQL)
'Test to see if word is in the Not_Used table if not query tbl_IndexedWords and openrecordset
If rs.EOF Then
    mySQL = "SELECT * FROM tbl_IndexedWords WHERE tbl_IndexedWords = '" & UCaseWord & "'"
Set rs1 = CurrentDb.OpenRecordset(mySQL)
'Test to see if word is in the IndexedWords table if not then add the word to the IndexedWord table
    If rs1.EOF Then
    Set rs2 = CurrentDb.OpenRecordset("tbl_IndexedWords")
        rs2.AddNew
        rs2!Uppercase = UpWordCase
        rs2.Update
'If the word is in the tbl_IndexedWords then increase the count by 1
    Else
        rs1.Edit
        rs1!SumOfCount = rs2!SumOfCount + 1
        rs1.Update
    End If
'If the word is in the tbl_IndexedWord_Not_Used then increase the count by 1
Else
    rs.Update
    rs!SumOfCount = rs!SumOfCount + 1
    rs.Update
    
End If
Next
'Close all openrecordset
rs.close
rs1.close
rs2.close


End Sub
I get the error message at this point
Code:
Set rs = CurrentDb.OpenRecordset(strSQL)
 

KeithG

AWF VIP
Local time
Today, 02:15
Joined
Mar 23, 2006
Messages
2,592
Try DAO.Recordset instead of just Recordset.

There is both a DAO and ADODB recordset object in Access.
 

boblife42

Registered User.
Local time
Today, 02:15
Joined
May 30, 2008
Messages
32
Kinda new to this language how would change it to a DAO.Recordset
 

midmented

DP Programmer
Local time
Today, 05:15
Joined
Jun 5, 2008
Messages
94
The query string is wrong
Aren't you missing a semicolon there on the end?
(
strSQL = "SELECT * FROM tbl_IndexedWord_Not_Used WHERE tbl_IndexedWord_Not_Used = '" & UCaseWord & "'")

k, let me edit my comment....
Define the field your looking for as well.

strSQl = "SELECT * from tbl_IndexedWord_Not_Used WHERE tbl_IndexedWord_Not_Used.FIELDNAME ='" &UCaseWord & "';"
 
Last edited:

KeithG

AWF VIP
Local time
Today, 02:15
Joined
Mar 23, 2006
Messages
2,592
Just change Dim rs as Recordset to Dim rs as DAO.Recordset
 

midmented

DP Programmer
Local time
Today, 05:15
Joined
Jun 5, 2008
Messages
94
DLookup

Looking through your code, I would actually use a dlookup. Alot less code.
I hate opening recordsets if there is no need to do it.

Like:
Code:
'Split text into array from description problem textbox
strArray = Split(DescProblem)
For x = 0 To UBound(strArray)
'Change strArray to UPPERCASE
UCaseWord = UCase(strArray(x))
'Query tbl_IndexedWord_Not_Used

Dim blnWordFound as Boolean

'False if word is not found
blnWordFound = nz(DLookup("FIELDNAME","tbl_IndexedWord_Not_Used","[FIELDNAME] ='" & UCaseWord & "'"),False)

If blnWordFound = false then
 'Update the recordset
else
 'Nothing?
end if

Just an idea......
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:15
Joined
Aug 30, 2003
Messages
36,133
Are your field names actually the same as the table names?
 

KeithG

AWF VIP
Local time
Today, 02:15
Joined
Mar 23, 2006
Messages
2,592
What is the actual error message text?
 

midmented

DP Programmer
Local time
Today, 05:15
Joined
Jun 5, 2008
Messages
94
Name of Field?

You noticed that FIELDNAME is supposed to be whatever field the word is located in you are looking for?

What is the field name?
 

boblife42

Registered User.
Local time
Today, 02:15
Joined
May 30, 2008
Messages
32
Message:
Runtime Error '3061'
Too few Parameters Expected 1
 

KeithG

AWF VIP
Local time
Today, 02:15
Joined
Mar 23, 2006
Messages
2,592
I would assume tbl_IndexedWord_Not_Used is a table, correct? Look at you Where clause in the variable you donot have a field in it.
 

midmented

DP Programmer
Local time
Today, 05:15
Joined
Jun 5, 2008
Messages
94
That runtime error usually means "There are too few parameters" which I think is because of the SQL strings. Simply having tbl_IndexedWord_Not_Used isn't telling it what field to look in for the data. You need to add the .FIELDNAME (change the bold part of the SQL statement below to whatever field you are looking in for the word)

strSQl = "SELECT * from tbl_IndexedWord_Not_Used WHERE tbl_IndexedWord_Not_Used.FIELDNAME ='" &UCaseWord & "';"

If the fieldname is the same as the tablename then

strSQl = "SELECT * from tbl_IndexedWord_Not_Used WHERE tbl_IndexedWord_Not_Used.tbl_IndexedWord_Not_Used ='" &UCaseWord & "';"
 

boblife42

Registered User.
Local time
Today, 02:15
Joined
May 30, 2008
Messages
32
Thank you that worked I feel silly for forgetting that, I had it written down.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 02:15
Joined
Aug 30, 2003
Messages
36,133
You don't actually need to specify both generally, but since the table and field names are the same, Access got confused. I'd change that if it's not too late.
 

Users who are viewing this thread

Top Bottom