Hello, I created a listbox with companies names and when the user selects a company a report is generated based on the company name. I created a Function below and then I created a button that will call the function and the report will be generated. If I dont select any field the report is generated showing me all fileds otherwise it gives me an error that it cannot find the company name. Can someone help me?
Thank you in advanced
[code=vb]
Private Function GetCriteria() As String
Dim stDocCriteria As String
Dim VarItm As Variant
For Each VarItm In LstSenderCompan y.ItemsSelected
stDocCriteria = stDocCriteria & "[Sender_CompanyN ame] = " & LstSenderCompan y.Column(0, VarItm) & " OR "
Next
If stDocCriteria <> "" Then
stDocCriteria = Left(stDocCrite ria, Len(stDocCriter ia) - 4)
Else
stDocCriteria = "True"
End If
GetCriteria = stDocCriteria
End Function
Private Sub cmdSenderCompan y_Click()
DoCmd.OpenRepor t "rptSenderCompa ny", acViewPreview, , GetCriteria()
[/code]
Thank you in advanced
[code=vb]
Private Function GetCriteria() As String
Dim stDocCriteria As String
Dim VarItm As Variant
For Each VarItm In LstSenderCompan y.ItemsSelected
stDocCriteria = stDocCriteria & "[Sender_CompanyN ame] = " & LstSenderCompan y.Column(0, VarItm) & " OR "
Next
If stDocCriteria <> "" Then
stDocCriteria = Left(stDocCrite ria, Len(stDocCriter ia) - 4)
Else
stDocCriteria = "True"
End If
GetCriteria = stDocCriteria
End Function
Private Sub cmdSenderCompan y_Click()
DoCmd.OpenRepor t "rptSenderCompa ny", acViewPreview, , GetCriteria()
[/code]
Comment