stLinkCriteria - with Multiple criteria

B

Berny

Hello,

I'm having a problem using stLinkCriteria; I'm trying to also include a
multi-list box selection into my criteria.

I'm at the end of my rope trying to make this work.

Can anyone give me a push in the right dirrection?

I'm using the following code to make the multi-list selection

If Me!TradeSelection.ItemsSelected.Count > 0 Then
For Each varTradeItem In Me!TradeSelection.ItemsSelected
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & "OR "

Next varTradeItem
strTradeCriteria = Left(strTradeCriteria, Len(strTradeCriteria) - 3)
Else
MsgBox "You have not made a selection" , vbExclamation, "Nothing to
find!"
End If

Then I'm trying to add another field on the form called SBKG to the
LinkCriteria

stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And [Trade]= '" &
strTradeCriteria & "'"

The goal is to open the following report but I can't figure-out what I doing
wrong

DoCmd.OpenReport strDocName, acViewPreview, , stLinkCriteria

I would greatly appreciate any help anyone can provide

Thank you
 
G

Guest

I am working on almost an identical problem. Some of the reports are not yet
done, so you will see some gaps in the code, but this is the essence of it.
Example 1 shows how I build the Where Condition from multiple list boxes
with multiple selections.
Example 2 shows how I put together the where condition from the various list
boxes

**********Example 1************************
Private Sub PrintReport(lngView As Long)
Dim strWhere As String 'String that will hold filtering as selected on
form
Dim strWhereNext As String 'Used to concantenate multiple field selections
Dim strDocName As String 'The Report version to open
Dim strFieldName As String 'The field name to include in the Where Condition

'Billable Product Offering
strWhere = BuildWhereCondition("lstBillProdOffering")
strFieldName = "tblBudgetVSActualLbrPO.BillableProductOffering "
If Len(strWhere) > 0 Then
strWhere = strFieldName & strWhere
End If
'Master Activity
strWhereNext = BuildWhereCondition("lstMActivity")
strFieldName = "tblMasterActivity.MActivity "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'Activity
strWhereNext = BuildWhereCondition("lstActivity")
strFieldName = "tblBudgetVSActualLbrPO.Activity "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'BillNetwork
strWhereNext = BuildWhereCondition("lstBillNetwork")
strFieldName = "tblActivity.actvContractActivity "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'Pool
strWhereNext = BuildWhereCondition("lstPool")
strFieldName = "tblBudgetVSActualLbrPO.Pool "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'Home Room
strWhereNext = BuildWhereCondition("lstHomeRoom")
strFieldName = "tblBudgetVSActualLbrPO.acctgunit "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
Select Case Me.opgReportFormat
Case 1 'By Product Offering
Case 2 'By Master Activity
Case 3 'By Activity
strDocName = "rptPVAByActivityPO"
Case 4 'By By BillNetwork
Case 5 'By By Pool
Case 6 'By Home Room
strDocName = "rptPVAByAcctgUnitPO"
End Select

DoCmd.OpenReport strDocName, lngView, , strWhere

End Sub

*************Example 2
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
***********End Code******************

Berny said:
Hello,

I'm having a problem using stLinkCriteria; I'm trying to also include a
multi-list box selection into my criteria.

I'm at the end of my rope trying to make this work.

Can anyone give me a push in the right dirrection?

I'm using the following code to make the multi-list selection

If Me!TradeSelection.ItemsSelected.Count > 0 Then
For Each varTradeItem In Me!TradeSelection.ItemsSelected
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & "OR "

Next varTradeItem
strTradeCriteria = Left(strTradeCriteria, Len(strTradeCriteria) - 3)
Else
MsgBox "You have not made a selection" , vbExclamation, "Nothing to
find!"
End If

Then I'm trying to add another field on the form called SBKG to the
LinkCriteria

stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And [Trade]= '" &
strTradeCriteria & "'"

The goal is to open the following report but I can't figure-out what I doing
wrong

DoCmd.OpenReport strDocName, acViewPreview, , stLinkCriteria

I would greatly appreciate any help anyone can provide

Thank you
 
S

Steve Schapel

Benny,

You're certainly on the right track. It looks like you have omitted a
space before the OR and I think this will make a difference, i.e. try it
like this...
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & " OR "
And then this means, of course, that the next line will scrap the last 4
characters instead of 3.

And then, in your definition of stLinkCriteria, you do not need the bit
about [Trade]=
The way this is written, it will evaluate like this...
... And [Trade]='Trade='FirstItem' Or Trade='SecondItem' '

Try it like this...
stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And " & strTradeCriteria

If there is still a problem, try temporarily putting a line in your code
after the stLinkCriteria = line, like this...
MsgBox stLinkCriteria
and then have a look at that output it might give a clue what is wrong.
 
B

Berny

Thank you

Klatuu said:
I am working on almost an identical problem. Some of the reports are not
yet
done, so you will see some gaps in the code, but this is the essence of
it.
Example 1 shows how I build the Where Condition from multiple list boxes
with multiple selections.
Example 2 shows how I put together the where condition from the various
list
boxes

**********Example 1************************
Private Sub PrintReport(lngView As Long)
Dim strWhere As String 'String that will hold filtering as selected
on
form
Dim strWhereNext As String 'Used to concantenate multiple field
selections
Dim strDocName As String 'The Report version to open
Dim strFieldName As String 'The field name to include in the Where
Condition

'Billable Product Offering
strWhere = BuildWhereCondition("lstBillProdOffering")
strFieldName = "tblBudgetVSActualLbrPO.BillableProductOffering "
If Len(strWhere) > 0 Then
strWhere = strFieldName & strWhere
End If
'Master Activity
strWhereNext = BuildWhereCondition("lstMActivity")
strFieldName = "tblMasterActivity.MActivity "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'Activity
strWhereNext = BuildWhereCondition("lstActivity")
strFieldName = "tblBudgetVSActualLbrPO.Activity "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'BillNetwork
strWhereNext = BuildWhereCondition("lstBillNetwork")
strFieldName = "tblActivity.actvContractActivity "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'Pool
strWhereNext = BuildWhereCondition("lstPool")
strFieldName = "tblBudgetVSActualLbrPO.Pool "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
'Home Room
strWhereNext = BuildWhereCondition("lstHomeRoom")
strFieldName = "tblBudgetVSActualLbrPO.acctgunit "
If Len(strWhereNext) > 0 Then
If Len(strWhere) > 0 Then
strWhere = strWhere & " AND " & strFieldName & strWhereNext
Else
strWhere = strFieldName & strWhereNext
End If
End If
Select Case Me.opgReportFormat
Case 1 'By Product Offering
Case 2 'By Master Activity
Case 3 'By Activity
strDocName = "rptPVAByActivityPO"
Case 4 'By By BillNetwork
Case 5 'By By Pool
Case 6 'By Home Room
strDocName = "rptPVAByAcctgUnitPO"
End Select

DoCmd.OpenReport strDocName, lngView, , strWhere

End Sub

*************Example 2
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
***********End Code******************

Berny said:
Hello,

I'm having a problem using stLinkCriteria; I'm trying to also include a
multi-list box selection into my criteria.

I'm at the end of my rope trying to make this work.

Can anyone give me a push in the right dirrection?

I'm using the following code to make the multi-list selection

If Me!TradeSelection.ItemsSelected.Count > 0 Then
For Each varTradeItem In Me!TradeSelection.ItemsSelected
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & "OR "

Next varTradeItem
strTradeCriteria = Left(strTradeCriteria, Len(strTradeCriteria) -
3)
Else
MsgBox "You have not made a selection" , vbExclamation, "Nothing
to
find!"
End If

Then I'm trying to add another field on the form called SBKG to the
LinkCriteria

stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And [Trade]= '" &
strTradeCriteria & "'"

The goal is to open the following report but I can't figure-out what I
doing
wrong

DoCmd.OpenReport strDocName, acViewPreview, , stLinkCriteria

I would greatly appreciate any help anyone can provide

Thank you
 
B

Berny

Thank you

Steve Schapel said:
Benny,

You're certainly on the right track. It looks like you have omitted a
space before the OR and I think this will make a difference, i.e. try it
like this...
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & " OR "
And then this means, of course, that the next line will scrap the last 4
characters instead of 3.

And then, in your definition of stLinkCriteria, you do not need the bit
about [Trade]=
The way this is written, it will evaluate like this...
... And [Trade]='Trade='FirstItem' Or Trade='SecondItem' '

Try it like this...
stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And " & strTradeCriteria

If there is still a problem, try temporarily putting a line in your code
after the stLinkCriteria = line, like this...
MsgBox stLinkCriteria
and then have a look at that output it might give a clue what is wrong.

--
Steve Schapel, Microsoft Access MVP

Hello,

I'm having a problem using stLinkCriteria; I'm trying to also include a
multi-list box selection into my criteria.

I'm at the end of my rope trying to make this work.

Can anyone give me a push in the right dirrection?

I'm using the following code to make the multi-list selection

If Me!TradeSelection.ItemsSelected.Count > 0 Then
For Each varTradeItem In Me!TradeSelection.ItemsSelected
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & "OR "

Next varTradeItem
strTradeCriteria = Left(strTradeCriteria, Len(strTradeCriteria) -
3)
Else
MsgBox "You have not made a selection" , vbExclamation, "Nothing
to
find!"
End If

Then I'm trying to add another field on the form called SBKG to the
LinkCriteria

stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And [Trade]= '" &
strTradeCriteria & "'"

The goal is to open the following report but I can't figure-out what I
doing wrong

DoCmd.OpenReport strDocName, acViewPreview, , stLinkCriteria

I would greatly appreciate any help anyone can provide

Thank you
 
B

Berny

Thank you VERY MUCH!!!!

It works exactly the way I was trying to make it work.

Steve Schapel said:
Benny,

You're certainly on the right track. It looks like you have omitted a
space before the OR and I think this will make a difference, i.e. try it
like this...
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & " OR "
And then this means, of course, that the next line will scrap the last 4
characters instead of 3.

And then, in your definition of stLinkCriteria, you do not need the bit
about [Trade]=
The way this is written, it will evaluate like this...
... And [Trade]='Trade='FirstItem' Or Trade='SecondItem' '

Try it like this...
stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And " & strTradeCriteria

If there is still a problem, try temporarily putting a line in your code
after the stLinkCriteria = line, like this...
MsgBox stLinkCriteria
and then have a look at that output it might give a clue what is wrong.

--
Steve Schapel, Microsoft Access MVP

Hello,

I'm having a problem using stLinkCriteria; I'm trying to also include a
multi-list box selection into my criteria.

I'm at the end of my rope trying to make this work.

Can anyone give me a push in the right dirrection?

I'm using the following code to make the multi-list selection

If Me!TradeSelection.ItemsSelected.Count > 0 Then
For Each varTradeItem In Me!TradeSelection.ItemsSelected
strTradeCriteria = strTradeCriteria & "Trade = " & Chr(34) &
Me!TradeSelection.ItemData(varTradeItem) & Chr(34) & "OR "

Next varTradeItem
strTradeCriteria = Left(strTradeCriteria, Len(strTradeCriteria) -
3)
Else
MsgBox "You have not made a selection" , vbExclamation, "Nothing
to
find!"
End If

Then I'm trying to add another field on the form called SBKG to the
LinkCriteria

stLinkCriteria = "[SBKG]= '" & Me![cboSBKG] & "' And [Trade]= '" &
strTradeCriteria & "'"

The goal is to open the following report but I can't figure-out what I
doing wrong

DoCmd.OpenReport strDocName, acViewPreview, , stLinkCriteria

I would greatly appreciate any help anyone can provide

Thank you
 

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