Build report criteria outof listbox

S

SF

Hi,

I have a form with a listbox that listed Contract ID.
I want to construct a strinf criteria for the report that look like
[Ck_ContractID]='FOG-123' OR [Ck_ContractID]='FOG-124' OR
[Ck_ContractID]='FOG-144'


dim gstrReportFilter as string

For Each varItem In Me.cmbContractNumber.ItemsSelected
gstrReportFilter = gstrReportFilter & gstrReportFilter =
"[Ck_ContractID]='" & Me.cmbContractNumber.ItemData(varItem) & "' OR
[Ck_ContractID]='"
Debug.Print gstrReportFilter '= " OR [Ck_ContractID]='"
'DoCmd.OpenReport Me.listReports, acViewPreview, , gstrReportFilter
''StgCriteria
Next varItem
DoCmd.OpenReport Me.listReports, acViewPreview, , gstrReportFilter

SF
 
J

John Spencer MVP

Perhaps something more like this snippit

dim strCheckContract

For Each varItem In Me.cmbContractNumber.ItemsSelected
strCheckContract = strCheckContract & "'" & _
Me.cmbContractNumber.ItemData(varItem) & ",
Next varItem
If Len(strCheckContract) > 0 then
strCheckContract = " Ck_Contract_ID IN (" & strCheckContract & ")"
If Len(gstrReportFilter) > 0 then
gstrReportFilter = gstrReportFilter & " AND "
End If
gstrReportFilter = gStrReportFilter & strCheckContract
End If

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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

Top