K
Kevin
I have a form with a first combo box - cboProjectName, that when selected
filters a second combo box - cboBidNumber. This serves as a parameter query
for various reports. I wish to change the second combo box to a multi-select
list box - now called lstBidNumber. I used some code that I found online as
a starting point. So far, I select the "ProjectName", and it properly gives
me the available "BidNumber" selections.
When I click on any BidNumber, I get the following error message: Run Time
Error 2001 - "You cancelled the previous operation".
Here is the code I entered in the OnClick procedure for lstBidNumber:
Private Sub lstBidNumber_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryDialog")
For Each varItem In Me!lstBidNumber.ItemsSelected
strCriteria = strCriteria & ",'" & Me.lstBidNumber.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT * FROM Bid " & _
"WHERE Bid.BidNumber IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryDialog"
Set db = Nothing
Set qdf = Nothing
End Sub
I don't have too much experience with VB, so I am somewhat at a loss at how
to identify what is wrong. Should there be something in the AfterUpdate
event too?Any help would be greatly appreciated!!
filters a second combo box - cboBidNumber. This serves as a parameter query
for various reports. I wish to change the second combo box to a multi-select
list box - now called lstBidNumber. I used some code that I found online as
a starting point. So far, I select the "ProjectName", and it properly gives
me the available "BidNumber" selections.
When I click on any BidNumber, I get the following error message: Run Time
Error 2001 - "You cancelled the previous operation".
Here is the code I entered in the OnClick procedure for lstBidNumber:
Private Sub lstBidNumber_Click()
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryDialog")
For Each varItem In Me!lstBidNumber.ItemsSelected
strCriteria = strCriteria & ",'" & Me.lstBidNumber.ItemData(varItem) & "'"
Next varItem
If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If
strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT * FROM Bid " & _
"WHERE Bid.BidNumber IN(" & strCriteria & ");"
qdf.SQL = strSQL
DoCmd.OpenQuery "qryDialog"
Set db = Nothing
Set qdf = Nothing
End Sub
I don't have too much experience with VB, so I am somewhat at a loss at how
to identify what is wrong. Should there be something in the AfterUpdate
event too?Any help would be greatly appreciated!!