By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,715 Members | 1,773 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,715 IT Pros & Developers. It's quick & easy.

I need HELP with error "Too few parameters..."

P: n/a
Greetings Experts ...

I have a routine that is invoked when a command button is clicked. The
button is located in a form that is tied to a table of Project records.
Each Project Record has 0 to many Task Records associated with it (in
another table). I want to 'logically remove' the Project Record and all
Task Records for the Project (by setting the [removed] field in each of
those records to 'true').

Here is the problem ... in the routine I define the database as the
'currentDB' and setup an SQL statement to select the necessary Task
records. It get this error:
"Too few parameters. Expected 1." for the following statement:

set rs = db.OpenRecordset(strSQL)

I have traced the code and the strSQL field is setup at the time the
'set' command is hit. I am self-taught and don't really understand the
difference between DAO and ADODB, so that might be the problem.
However, I use the DAO commands to reference 'recordsets' all over this
particular "mdb" and have never seen this particular error before. Does
anyone have any ideas for me?

Here is the entire routine (in case you need to see it):

Private Sub btnRemove_Click()
On Error GoTo Err_btnRemove_Click

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim ans As String
Dim rcount As Integer

ans = MsgBox("You are about to REMOVE this project and it's tasks. "
& _
"Are you SURE?", vbExclamation + vbOKCancel, "Are you
SURE?")
If ans = vbNo Then GoTo Exit_btnRemove_Click

strSQL = "SELECT * FROM tblTasks " & _
"WHERE [relID] = '" & Me!relID & "' " & _
"AND [projID] = " & Me!projID & " " & _
"AND [removed] = False"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

If Not rs.EOF Then
With rs
.MoveFirst
rcount = 1
Do Until .EOF
.Edit
!removed = True
.Update
Debug.Print "Task # " & rcount & " has been removed"
.MoveNext
rcount = rcount + 1
Loop
End With
End If

rs.Close

'Now Remove the Project Record
Me.AllowEdits = True
Me!removed = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
refresh_list 'routine to refresh the screen

Debug.Print "Project has been removed"
Me!AllowEdits = False

Exit_btnRemove_Click:
Exit Sub

Err_btnRemove_Click:
MsgBox Err.Description & Module_Name & " btnRemove_Click"
Resume Exit_btnRemove_Click

End Sub
Thanks, again.
- Sue

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
One of the fields in your query for tblTasks, [relID], [projID] or
[removed], is not a valid field name in tblTasks. Thus the query thinks
that that one field is a parameter; thus, you get the message "Too few
parameters. Expected 1.". Check the field names referenced in your strSQL
string against the actual field names in the table, correct the incorrect
one and try again.

"Susan Bricker" <sb****@att.net> wrote in message
news:40**********************@news.newsgroups.ws.. .
Greetings Experts ...

I have a routine that is invoked when a command button is clicked. The
button is located in a form that is tied to a table of Project records.
Each Project Record has 0 to many Task Records associated with it (in
another table). I want to 'logically remove' the Project Record and all
Task Records for the Project (by setting the [removed] field in each of
those records to 'true').

Here is the problem ... in the routine I define the database as the
'currentDB' and setup an SQL statement to select the necessary Task
records. It get this error:
"Too few parameters. Expected 1." for the following statement:

set rs = db.OpenRecordset(strSQL)

I have traced the code and the strSQL field is setup at the time the
'set' command is hit. I am self-taught and don't really understand the
difference between DAO and ADODB, so that might be the problem.
However, I use the DAO commands to reference 'recordsets' all over this
particular "mdb" and have never seen this particular error before. Does
anyone have any ideas for me?

Here is the entire routine (in case you need to see it):

Private Sub btnRemove_Click()
On Error GoTo Err_btnRemove_Click

Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim ans As String
Dim rcount As Integer

ans = MsgBox("You are about to REMOVE this project and it's tasks. "
& _
"Are you SURE?", vbExclamation + vbOKCancel, "Are you
SURE?")
If ans = vbNo Then GoTo Exit_btnRemove_Click

strSQL = "SELECT * FROM tblTasks " & _
"WHERE [relID] = '" & Me!relID & "' " & _
"AND [projID] = " & Me!projID & " " & _
"AND [removed] = False"

Set db = CurrentDb
Set rs = db.OpenRecordset(strSQL)

If Not rs.EOF Then
With rs
.MoveFirst
rcount = 1
Do Until .EOF
.Edit
!removed = True
.Update
Debug.Print "Task # " & rcount & " has been removed"
.MoveNext
rcount = rcount + 1
Loop
End With
End If

rs.Close

'Now Remove the Project Record
Me.AllowEdits = True
Me!removed = True
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70
refresh_list 'routine to refresh the screen

Debug.Print "Project has been removed"
Me!AllowEdits = False

Exit_btnRemove_Click:
Exit Sub

Err_btnRemove_Click:
MsgBox Err.Description & Module_Name & " btnRemove_Click"
Resume Exit_btnRemove_Click

End Sub
Thanks, again.
- Sue

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 13 '05 #2

P: n/a
Hey .. ByteMyzer
Boy is my face red. Thanks for the catch. Funny, when I wrote that
statement, I thought I should double check my shortterm memory and look
at the table to see if I got the fields right. I should have. After
correcting the SELECT statement, it worked. Thanks so much.

-SB

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.