Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combo Box

Status
Not open for further replies.

suratbali

Technical User
Jan 15, 2003
11
ID
I make a report. Before the report appear you must choose the data form combo box. HOw to make a combo box that can choose more than one data
 
If it's possible, you might consider using a list box.
Within list boxes there is a property called 'Multi Select' that will allow the user to select more than one item from a list. You can either set it (the Multi Select property) to Simple, which will not require the user to hold Shift or Control when making a multiple selection, or Extended which will require it.

You may already have this part figured out, but to get a query/report to pull for more than one item in the list you will also need to include a For Each loop that will loop through the list and only look at the items you've selected.

It would look something (but not exactly it depends on your situation) like this...

'Declare variable.
Dim var

'Begin loop.
For each var in me.NameofYourListBox(ItemsSelected)

'Generate report for each value selected.
DoCmd.OpenReport "YourReport"

'Loop back to next item selected.
Next var

hope this helps you.

 
You can't. But if you use a list box, the user will be able to choose more than 1 item in the list box. Then you can call the following procedure which will create a query that the report will use as its Recordsource.

Note that Lst is the name of your list box.

Code:
    Dim dbs As DAO.Database
    Dim qdf As DAO.QueryDef

    Dim strSQL As String
    Dim strSQLWhere As String
    Dim varItem As Variant
    
    On Error GoTo ErrHandler
    
    strSQLWhere = vbNullString
    
'***************************************************
'*  Loop thru list box to build your Where clause  *
'***************************************************

    If (Lst.ItemsSelected.Count > 0) Then
    
        strSQLWhere = " Where "
        
        For Each varItem In Lst.ItemsSelected
            strSQLWhere = strSQLWhere & "YourFieldName=" & Lst.Column(0, varItem) & " OR "
        Next varItem
        
        strSQLWhere = Left(strSQLWhere, Len(strSQLWhere) - 4) 'get rid of last or
    
    End If
    
    strSQL = "Select * Form YourTable " & strSQLWhere
    
'************************************************
'*  Delete original query and create a new one  *
'************************************************

    Set dbs = CurrentDb
    dbs.QueryDefs.Delete "qryNameOfYourQuery"
    Set qdf = dbs.CreateQueryDef("qryNameOfYourQuery", strSQL)
    strSQL = vbNullString
    DoEvents

ExitProcedure:
    Exit Sub

ErrHandler:
    If (Err.Number = 3265) Then 'IFT, tryed to delete a query that did not exist
        Resume Next
    Else
        MsgBox Err.Number & Err.Description
        Resume ExitProcedure
    End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top