Form Design

G

Guest

I have a form in which I want the user to have the option to selecting up to
15 employees. I also want to query these 15 names to provide reports based
on the employee's name. Should I create a separate table for the
employeenames and insert a sub-form and make it continuous?

Thanks
 
G

Guest

In a situation like this, I would use a Multi Select List Box with the Multi
Select property set to extended.
Then to use the items selected by the user, you will need to use the
ItemsSelected collection of the list box to determine which employees the
user has selected. There is a good example in VBA Help of how to use this
collection.

Here is a function I use for a similar situation:

Private Function BuildWhereCondition(strControl As String) As String
'Set up the WhereCondition Argument for the reports
Dim varItem As Variant
Dim strWhere As String
Dim ctl As Control

Set ctl = Me.Controls(strControl)

Select Case ctl.ItemsSelected.Count
Case 0 'Include All
strWhere = ""
Case 1 'Only One Selected
strWhere = "= '" & _
ctl.ItemData(ctl.ItemsSelected(0)) & "'"
Case Else 'Multiple Selection
strWhere = " IN ("

With ctl
For Each varItem In .ItemsSelected
strWhere = strWhere & "'" & .ItemData(varItem) & "', "
Next varItem
End With
strWhere = Left(strWhere, Len(strWhere) - 2) & ")"
End Select

BuildWhereCondition = strWhere

End Function

It returns a string that will filter your report based on the items
selected. You call it by passing the name of the ListBox as as string to the
function and then open your report using it:

DoCmd.OpenReport "MyReportName", , , BuildWhere("MyListBoxName")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Display Continuous Form Alongside a Datasheet. 7
Data from from field not found in table 1
Data Entry Form. 3
Access Form Refresh 1
Button Caption help 3
Excel List Box Help 1
Excel List Box 5
Look up employee name in Form 3

Top