C
carrietom
Hi, this is driving me crazy. I have copied some code generously provided by
some expert out there to build some list boxes where the user can select from
a list and display the selected items in another box (also filling these
selections into a junction table). There's a command button to add the items
and another command button to remove the items. The button to remove items
from the list gives a run-time error '3075': extra ) in query expression
'Near_Miss_ID=2 AND (Detail_Link_ID=)'.
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.SelectedDirectCause.ItemsSelected
strwhere = strwhere & "Detail_Link_ID=" &
Me.SelectedDirectCause.ItemData(varItem) & " OR"
Next varItem
strwhere = Left(strwhere, Len(strwhere) - 4)
strSQL = "Delete * from Near_Miss_Detail_TBL where Near_Miss_ID=" &
Me.Near_Miss_ID & " AND (" & strwhere & ");"
Set db = CurrentDb
db.Execute strSQL
Me.ListDirectCause.Requery
Me.SelectedDirectCause.Requery
Set db = Nothing
End Sub
I have tried removing some of the brackets, but I just generate other errors
about missing syntax. Can anyone spot my error here? Thanks as always!
BTW, not sure if it matters but there is a difference in that I built this
as a subform to go in a main form which is what the Near_Miss_ID relates to.
I have a Near_Miss_ID in both my Main Form and Subform (the current record
number is 2 which is what I'm assuming the =2 is referring to in the error
message)
some expert out there to build some list boxes where the user can select from
a list and display the selected items in another box (also filling these
selections into a junction table). There's a command button to add the items
and another command button to remove the items. The button to remove items
from the list gives a run-time error '3075': extra ) in query expression
'Near_Miss_ID=2 AND (Detail_Link_ID=)'.
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.SelectedDirectCause.ItemsSelected
strwhere = strwhere & "Detail_Link_ID=" &
Me.SelectedDirectCause.ItemData(varItem) & " OR"
Next varItem
strwhere = Left(strwhere, Len(strwhere) - 4)
strSQL = "Delete * from Near_Miss_Detail_TBL where Near_Miss_ID=" &
Me.Near_Miss_ID & " AND (" & strwhere & ");"
Set db = CurrentDb
db.Execute strSQL
Me.ListDirectCause.Requery
Me.SelectedDirectCause.Requery
Set db = Nothing
End Sub
I have tried removing some of the brackets, but I just generate other errors
about missing syntax. Can anyone spot my error here? Thanks as always!
BTW, not sure if it matters but there is a difference in that I built this
as a subform to go in a main form which is what the Near_Miss_ID relates to.
I have a Near_Miss_ID in both my Main Form and Subform (the current record
number is 2 which is what I'm assuming the =2 is referring to in the error
message)