ADP list box filter

O

okschlaps

I tried posting this on the ADP site, but got no response. Maybe someone here
can help me. Thanks!
I need a little help understanding how filters work in ADP. I have a form
that worked in an mdb that allowed users to select multiple items from a list
box and have them applied as filters on a report.
When I try to run this in ADP i get "Error 207 - Invalid column name" and
then the value of the list box selection.
Below is the code (I believe I got it from an Allen Browne post) and I can't
find where it's misreading the filter as a column.

Private Sub cmdViewReport_Click()
On Error GoTo Err_Handler

Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

strDelim = """"
strDoc = "rptWksht_byTRS"

With Me.lstTRS
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text
strDescription = strDescrip & """" & .Column(1, varItem) &
""","
End If
Next
End With

lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[T-R-S] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Township-Range,Section: " & Left$(strDescrip,
lngLen)
End If
End If

'Report will not filter if open
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
 
O

okschlaps

the VBA doesn't seem to allow that

S.Clark said:
WAG: Change the delimiter to an apostrophe instead of double quote?

okschlaps said:
I tried posting this on the ADP site, but got no response. Maybe someone here
can help me. Thanks!
I need a little help understanding how filters work in ADP. I have a form
that worked in an mdb that allowed users to select multiple items from a list
box and have them applied as filters on a report.
When I try to run this in ADP i get "Error 207 - Invalid column name" and
then the value of the list box selection.
Below is the code (I believe I got it from an Allen Browne post) and I can't
find where it's misreading the filter as a column.

Private Sub cmdViewReport_Click()
On Error GoTo Err_Handler

Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

strDelim = """"
strDoc = "rptWksht_byTRS"

With Me.lstTRS
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text
strDescription = strDescrip & """" & .Column(1, varItem) &
""","
End If
Next
End With

lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[T-R-S] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Township-Range,Section: " & Left$(strDescrip,
lngLen)
End If
End If

'Report will not filter if open
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
 
S

S.Clark

strDelim = "'"
strDelim = chr$(34)

What's doing with the OpenArgs?

okschlaps said:
the VBA doesn't seem to allow that

S.Clark said:
WAG: Change the delimiter to an apostrophe instead of double quote?

okschlaps said:
I tried posting this on the ADP site, but got no response. Maybe someone here
can help me. Thanks!
I need a little help understanding how filters work in ADP. I have a form
that worked in an mdb that allowed users to select multiple items from a list
box and have them applied as filters on a report.
When I try to run this in ADP i get "Error 207 - Invalid column name" and
then the value of the list box selection.
Below is the code (I believe I got it from an Allen Browne post) and I can't
find where it's misreading the filter as a column.

Private Sub cmdViewReport_Click()
On Error GoTo Err_Handler

Dim varItem As Variant
Dim strWhere As String
Dim strDescrip As String
Dim lngLen As Long
Dim strDelim As String
Dim strDoc As String

strDelim = """"
strDoc = "rptWksht_byTRS"

With Me.lstTRS
For Each varItem In .ItemsSelected
If Not IsNull(varItem) Then
'Build up the filter
strWhere = strWhere & strDelim & .ItemData(varItem) &
strDelim & ","
'Build up the description from the text
strDescription = strDescrip & """" & .Column(1, varItem) &
""","
End If
Next
End With

lngLen = Len(strWhere) - 1
If lngLen > 0 Then
strWhere = "[T-R-S] IN (" & Left$(strWhere, lngLen) & ")"
lngLen = Len(strDescrip) - 2
If lngLen > 0 Then
strDescrip = "Township-Range,Section: " & Left$(strDescrip,
lngLen)
End If
End If

'Report will not filter if open
If CurrentProject.AllReports(strDoc).IsLoaded Then
DoCmd.Close acReport, strDoc
End If

DoCmd.OpenReport strDoc, acViewPreview, WhereCondition:=strWhere,
OpenArgs:=strDescrip

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then 'Ignore "Report cancelled" error.
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdPreview_Click"
End If
Resume Exit_Handler

End Sub
 

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