Gasman
Enthusiastic Amateur
- Local time
- Today, 17:31
- Joined
- Sep 21, 2011
- Messages
- 14,323
PMFJI, but your code looks like it is processing EVERY item in the list box, not just the ones you have selected. You should see that when you step through the code?
jddraw gave you a hint with the links to .ItemsSelected
https://msdn.microsoft.com/en-us/library/office/ff823015.aspx?f=255&MSPPError=-2147217396
If this is not the case, then my apologies.
Also Do.Cmd.OutputTo does not appear to have a parameter for criteria?
https://msdn.microsoft.com/en-us/library/office/ff192065.aspx
I think you will need DoCmd.OpenReport which you were using and specify the criteria correctly.
Here is a sample of code I have used in the past. This prints out a report dependant on the value in the combo box. Ignore the CopyObject, I had to use that to get the pdf in the correct name as I am on 2003. Also try closing the report each time. That might fix your one big report problem?
jddraw gave you a hint with the links to .ItemsSelected
https://msdn.microsoft.com/en-us/library/office/ff823015.aspx?f=255&MSPPError=-2147217396
If this is not the case, then my apologies.
Also Do.Cmd.OutputTo does not appear to have a parameter for criteria?
https://msdn.microsoft.com/en-us/library/office/ff192065.aspx
I think you will need DoCmd.OpenReport which you were using and specify the criteria correctly.
Here is a sample of code I have used in the past. This prints out a report dependant on the value in the combo box. Ignore the CopyObject, I had to use that to get the pdf in the correct name as I am on 2003. Also try closing the report each time. That might fix your one big report problem?
Code:
Private Sub cmdShip_Click()
On Error GoTo Err_cmdShip_Click
Dim stRptName As String, stParam As String, stLinkCriteria As String
Dim iPreview As Integer, iDialog As Integer
iPreview = 0
iDialog = 0
If Me.ChkPreview Then
iPreview = 2
iDialog = 3
End If
stRptName = "Main_by_Ship"
stParam = Replace(LCase(Me.cboShip.value), " ", "_")
stLinkCriteria = "[Ship] = '" & Me.cboShip.value & "'"
DoCmd.CopyObject , stParam, acReport, stRptName
DoCmd.OpenReport stParam, iPreview, , stLinkCriteria, iDialog
DoCmd.Close acReport, stParam
DoCmd.DeleteObject acReport, stParam
Exit_cmdShip_Click:
Exit Sub
Err_cmdShip_Click:
MsgBox Err.description
Resume Exit_cmdShip_Click
End Sub
Last edited: