A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

List box



 
 
Thread Tools Display Modes
  #1  
Old September 17th, 2009, 09:30 PM posted to microsoft.public.access.forms
PJ
external usenet poster
 
Posts: 265
Default List box

I would like to have a list box in a form based off of a query that you can
select multiple criteria and a report would produce off of what was selected.
How would I do that?


Thanks in advance
  #2  
Old September 17th, 2009, 11:37 PM posted to microsoft.public.access.forms
Kipp Woodard
external usenet poster
 
Posts: 50
Default List box

You will probably want your ListBox [Multi Select] property to be set to
"Extended".

Then, the approach I would use would be to build the Where clause for my
report's record source in VBA, stringing together the selected values.

Here's the code to do that.
=================
Option Compare Database
Option Explicit

Private Sub cmdOpenReport_Click()
Const PROC_NAME As String = "cmdOpenReport_Click"

Dim vItem As Variant
Dim sWhereClause As String

On Error GoTo ErrorHandler

If Me.lstSelections.ItemsSelected.Count = 0 Then
Exit Sub
End If

' Change FieldName below to the name of your field.
sWhereClause = "[FieldName] In ("

' Loop the selected items.
For Each vItem In Me.lstSelections.ItemsSelected
' Add the value of the current selection to the Where clause.
sWhereClause = sWhereClause & """" &
Me.lstSelections.ItemData(vItem) & """, "
Next

' Trim off the final ", "
sWhereClause = Left(sWhereClause, Len(sWhereClause) - 2)

' Close the parens.
sWhereClause = sWhereClause & ")"

' Change MyReportName below to the name of your report.
DoCmd.OpenReport "MyReportName", acViewPreview, , sWhereClause

Cleanup:
Exit Sub

ErrorHandler:
MsgBox "Error: " & Err.Number & ", " & Err.Description, , Me.Name & "."
& PROC_NAME

On Error Resume Next

GoTo Cleanup

End Sub
==================
End of code

"PJ" wrote:

I would like to have a list box in a form based off of a query that you can
select multiple criteria and a report would produce off of what was selected.
How would I do that?


Thanks in advance

  #3  
Old September 18th, 2009, 01:08 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default List box

See:
Use a multi-select list box to filter a report
at:
http://allenbrowne.com/ser-50.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"PJ" wrote in message
...
I would like to have a list box in a form based off of a query that you
can
select multiple criteria and a report would produce off of what was
selected.
How would I do that?


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:30 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.