Sanda Daigle Listbox Error

C

CJ

Hi Groupies:

I am using the SelectRecords listbox example from Sandra Daigle in an Access
2007 database.

Everything is working fine except when I go to remove a selected item from
the right hand box to the left hand box.
I get the error "Run time error 3061" "Too few parameters. Expected 1".

I have tried to everything the same because I had no idea how to do this
myself.
The only thing that I see as being different is where she has ClassID
(autonumber) I have strSKUNumber (text size 10)

My code is below:

Private Sub cmdRemoveOne_Click()
Dim strSQL As String
Dim strwhere As String
Dim db As DAO.Database
Dim varItem As Variant

For Each varItem In Me.lstTruckInventory.ItemsSelected
strwhere = strwhere & "strSKUNumber= " &
Me.lstTruckInventory.ItemData(varItem) & " Or "
' strwhere = strwhere & "ClassID= " & Me.lstSelected.ItemData(varItem) & "
Or " <code that Sandra had>
Next varItem
strwhere = Left(strwhere, Len(strwhere) - 4)
strSQL = "Delete * from tblTruckItems where lngTruckID=" & Me.lngTruckID & "
AND (" & strwhere & ");"
Set db = CurrentDb
db.Execute strSQL
Me.lstShopInventory.Requery
Me.lstTruckInventory.Requery

Set db = Nothing
End Sub


Can somebody please help me understand and fix the problem.
 
G

Graham Mandeno

Hi CJ

Is strSKUNumber a text field or numeric?

If it is text, then you will need to enclose the values from your listbox in
quotes.

Instead of:

strwhere = strwhere & "strSKUNumber= " _
& Me.lstTruckInventory.ItemData(varItem) & " Or "

you need:

strwhere = strwhere & "strSKUNumber= '" _
& Me.lstTruckInventory.ItemData(varItem) & "' Or "

(Note the two single-quote characters, one after the = and one before the
Or)
 
C

CJ

Perfect!!

Thanks Graham.

--
Thanks for taking the time!

CJ
---------------------------------------------------------
Know thyself, know thy limits....know thy newsgroups!
Graham Mandeno said:
Hi CJ

Is strSKUNumber a text field or numeric?

If it is text, then you will need to enclose the values from your listbox
in quotes.

Instead of:

strwhere = strwhere & "strSKUNumber= " _
& Me.lstTruckInventory.ItemData(varItem) & " Or "

you need:

strwhere = strwhere & "strSKUNumber= '" _
& Me.lstTruckInventory.ItemData(varItem) & "' Or "

(Note the two single-quote characters, one after the = and one before the
Or)
--
Good Luck :)

Graham Mandeno [Access MVP]
Auckland, New Zealand
 

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