Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access 2003 VBA SQL "Too few parameters" error

Tags:

sql

vba

ms-access

Dim sort_slots_sql As String
sort_slots_sql = _
    "select date, part, service, slot" & _
    " from ass_slots, ass_occasions" & _
    " where ass_slots.occasion = ass_occasions.occasion" & _
    " order by slot, service, date, part"
Set slots_rst = db.OpenRecordset(sort_slots_sql)

This gives a too few parameters error. One is expected. On another place in the code, there is an almost identical situation but there, two parameters are expected!

like image 553
Emanuel Berg Avatar asked Jan 09 '12 21:01

Emanuel Berg


1 Answers

I can't say conclusively, but I am 99% sure the problem is that you have included a field name in that query that doesn't exist in the table. Check all the fields names and make sure they are spelled exactly like they are in the table.

Also the "Date" field is a likely suspect since it is a reserved word in Access. I'd suggest not naming a field "Date". However, if you are stuck with that name, surround it with square brackets in all your queries like so:

Dim sort_slots_sql As String
sort_slots_sql = _
    "select [date], part, service, slot" & _
    " from ass_slots, ass_occasions" & _
    " where ass_slots.occasion = ass_occasions.occasion" & _
    " order by slot, service, [date], part"
Set slots_rst = db.OpenRecordset(sort_slots_sql)
like image 166
JohnFx Avatar answered Sep 25 '22 13:09

JohnFx