Passing 2 parameters to OpenRecordset, but still execution stops

P

paul.schrum

Access 2007, developing an Access 2003 database.

In the code which follows, Visual Basic stops at the openRecordset
line with a messagebox stating

Run-time error 3061:

Too few parameters. Expected 2.

Well I gave it two. Can someone explain to me what is going on and
how I should correct my code?

Private Sub mendLocalOrder()
Dim nextToLastNumber
Dim rst As DAO.Recordset
Set rst = CurrentDb().OpenRecordset("SELECT taskID, localOrder " &
_
"FROM tbl_tasks " & _
"WHERE personIDassignedTo =
me.cmb_assignTaskTo_createTasks " & _
" AND urgencyID = me.cmb_urgency_createTasks " & _
"ORDER BY localOrder", dbOpenDynaset)
With rst
If .RecordCount > 1 Then
.MoveLast
.MovePrevious
nextToLastNumber = ![localOrder]
.MoveLast
![localOrder] = nextToLastNumber + 1
.Update
ElseIf .RecordCount = 1 Then
![localOrder] = 100 * Me.cmb_urgency_createTasks + 1
.Update
End If
.Close
End With
Set rst = Nothing
End Sub
 
L

Lord Kelvan

you need to remove the objects form the double quotes

Set rst = CurrentDb().OpenRecordset("SELECT taskID, localOrder FROM
tbl_tasks WHERE personIDassignedTo = " &
me.cmb_assignTaskTo_createTasks.column(1) & " AND urgencyID = " &
me.cmb_urgency_createTasks & "ORDER BY localOrder", dbOpenDynaset)

try that

Regards
Kelvan
 
B

boblarson

Or, as shown, if you are not using numeric ID's use quotes (I just used the
first one as if it were text and the other as if it were numeric to show how
to do it for either.

Set rst = CurrentDb().OpenRecordset("SELECT taskID, localOrder " & _
"FROM tbl_tasks " & _
"WHERE personIDassignedTo ='" & me.cmb_assignTaskTo_createTasks & "' "& _
"AND urgencyID =" & me.cmb_urgency_createTasks & _
" ORDER BY localOrder", dbOpenDynaset)
--
Bob Larson
Access MVP
Free Tutorials and Samples at http://www.btabdevelopment.com

__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top