MultiSelect ListBox

ToddL

Registered User.
Local time
Today, 14:41
Joined
Aug 20, 2002
Messages
13
I have read many post regarding this topic but I can't figure out how to do this on my own. I am finding the code very confusing. I have attached my database.
What I would like to do is from the form frmByGrant, select items from the list box and click print preview and preview the report (rptByGrant) for these items. I have looked at all the code that is posted and read all the post but for the life of me I can't figure this out. Any help would be appreciated. Thanks Laurie
 

Attachments

Ok I think this might be what you are looking for. I added a temporary text box to allow you to see the values that are being selected from the list but you can always hide that or take it out altogether.

Hope this helps
Hayley
 

Attachments

Thanks for your reply and help. I will let you know how I make out.
Thanks again
Laurie
 
Thanks, that is what I am looking for.
Laurie
 
Thanks Hayley. Im am stuck with 97 for hours without XP here at work.
 
Hayley or anyone
How and where would I put a piece of code that would give a message saying that they have not selected an item. Thanks again for all your help.
Laurie
 
Hi Todd

Try somethng like

If IsNull(lstSelectGrant.Value) Then
MsgBox "Please select an entry"
End If

That should do it for you

Hayley
 
Hayley,
I can't figure out where to put the code, I keep getting error messages.
Thanks
Laurie
 
Hayley -

Thanks for posting that sample code. I've struggled with trying to understand multiselect list boxes and have never been able to get my brain around it. Finally, I GET IT!

Thanks so much.

E
 
Hi Laurie

Put the code under the print preview cmdbutton so everything you have is the same just add in the code in my above post, something like

Private Sub cmdPrintPreview_Click()
Dim vItm As Variant
Dim stWhat As String
Dim stCriteria As String
Dim stSQL As String
Dim loqd As QueryDef

If IsNull(lstSelectGrant.Value) Then
MsgBox "Please select an entry"
Exit Sub
Else
stWhat = "": stCriteria = ","
For Each vItm In Me!lstSelectGrant.ItemsSelected
stWhat = stWhat & Me!lstSelectGrant.ItemData(vItm)
stWhat = stWhat & stCriteria
Next vItm
Me!txtCriteria = CStr(left$(stWhat, Len(stWhat) - Len(stCriteria)))
Set loqd = CurrentDb.QueryDefs("qryMultiSelect")
stSQL = "SELECT * "
stSQL = stSQL & "FROM qryProjectTitle WHERE ProjectID"
stSQL = stSQL & " IN (" & Me!txtCriteria & ")"
loqd.SQL = stSQL
loqd.Close
DoCmd.OpenReport "rptByGrant", acViewPreview
Me.Form.Visible = False
End if
End Sub
 

Users who are viewing this thread

Back
Top Bottom