Discussion Locked

multiple selection in listbox

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
i want to pass the selections (single or multiple) of a listbox on a form to a query in access 2000. how is this accomplished? thanks.

5 replies

by sl-campbell

According to MS Kb Artikle Q260819 the cause of the problem could be one of two things:

1). There are too many characters in the message. This behavior has been documented with messages that contain between 98 and 2268 characters.
To correct: This reduce the message length.

2). The SendObject method runs more than one time in a procedure.

To correct this: When you only need to send a message without attaching Access objects, send the message by automating the Outlook or CollaborativeData Objects (CDO) object libraries.

For more help go to the MS Kb and do a search on the above artikle or use the following address:

http://support.microsoft.com/support/kb/articles/Q260/8/19.ASP?LN=EN-US&SD=gn&FR=0&qry=SendObject%20%20%26quot%3BMSAccess%20caused%20an%20invalid%20page%20fault%20in%20module%20KERNEL32.DLL%26quot%3B&rnk=1&src=DHCS_MSPSS_gn_SRCH&SPR=MSALL

(Watch out for any spaces in the URL)

by sl-campbell

WOW! I NEED A VACATION!

SORRY, I copied to the wrong window and was too fast hitting the ENTER key.

Below is my answer!

by sl-campbell

Dim iMaxIndex As Integer
Dim sSelection As String
Dim sFieldName As String

sFieldName = "Customer.CustomerID"

'get the highest index of the items in the list box.

iMaxIndex = List1.ListCount - Gc1

'Loop through the list of items For I = 0 To iMaxIndex

'Find the selected item
If List1.Selected(I) Then

'Move to the selected item
List1.ListIndex = I

'Build the selection or criteria string sSelection = sSelection & " OR " & sFieldName & "='" & List1.List(I) & "'"

End If

Next I

'Remove the first " OR "
sSelection = Replace(sSelection , " OR ", vbNullString, 1, 1)

'Now you can easily build a sql recordset using the sSelection string as criteria.

If you do not know when to go from there, then please send a message for more help.

by ckeenan

thanks a lot! you can imagine my consternation when i read the first response!!!!

This discussion is closed to new replies.