I just can't find it

F

Fay Yocum

I have this code that works as advertised, except that it doesn't limit the
dataset to only the inactive learners. I have the same data on another
button and it works find. Can anyone spot the obvious error?

Private Sub cmdAddressLabels_Click()
On Error GoTo Err_cmdAddressLabels_Click

'Error message if there are no selected records in the
'Department
If Forms!frmReports!lstAddressStatus.ItemsSelected.Count = 0 Then
MsgBox "Please select the status you need!", vbInformation
Exit Sub
End If

Dim stDocName As String
Dim strWhere1 As String
Dim strWhere As String

'This is the code that isn't working. There are no parameters on the
underlying query.
strWhere = "SELECT * WHERE qryAddressLabels.Inactive <> -1"

For Each varItm In lstAddressStatus.ItemsSelected
strWhere1 = strWhere1 & ", " & Chr(34) &
Me.lstAddressStatus.ItemData(varItm) & Chr(34)
Next varItm
strWhere1 = "Status In (" & Mid(strWhere1, 3) & ")"

stDocName = "rptAddressLabels"
DoCmd.OpenReport stDocName, acPreview, , strWhere1

Exit_cmdAddressLabels_Click:
Exit Sub

Err_cmdAddressLabels_Click:
MsgBox Err.Description
Resume Exit_cmdAddressLabels_Click

End Sub

Here is the code for the button that works properly.

Private Sub cmdTelephoneRecall_Click()
On Error GoTo Err_cmdTelephoneRecall_Click

'Error message if there are no selected records in the
'Department
If Forms!frmReports!lstGluDept.ItemsSelected.Count = 0 Then
MsgBox "No departments are selected!", vbInformation
Exit Sub
End If

Dim stDocName As String
Dim strWhere1 As String
Dim strWhere As String

strWhere = "SELECT * WHERE qryRecallTelephone.Inactive <> -1"

For Each varItm In lstGluDept.ItemsSelected
strWhere1 = strWhere1 & ", " & Chr(34) &
Me.lstGluDept.ItemData(varItm) & Chr(34)
Next varItm
strWhere1 = "PerDiem2Unit In (" & Mid(strWhere1, 3) & ")"

stDocName = "rptRecallTelephoneLandscape"
DoCmd.OpenReport stDocName, acPreview, , strWhere1

Exit_cmdTelephoneRecall_Click:
Exit Sub

Err_cmdTelephoneRecall_Click:
MsgBox Err.Description
Resume Exit_cmdTelephoneRecall_Click

End Sub

Thank you for your help.

Fay
 
F

Fay Yocum

I went back and looked I had put a parameter in the base query. I thought I
had removed it. So if you will forgive me can you help me with that the line
of code should be to limit the Inactive records using SQL? Thank you for
your help.

Fay
..
 

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