On Aug 26, 2:36*pm, "David W. Fenton" <NoEm...@SeeSignature.invalid>
wrote:
> DawnTreader <alanrt...@gmail.com> wrote innews:f1274a70-2bf2-407f-aad7-(E-Mail Removed)
> m:
>
> > i have been fighting it to actually print the reports in ascending
> > order of the ReportID. is there anything in this code that would
> > be causing it to come out randomly?
>
> I'd think your code would only print the last report in the list,
> since the DoCmd.OpenReport is called after the Loop that walks
> through the recordset.
>
> Also, I wonder if this line:
>
> * Me.sfrmutblPrintReportIDs.Requery
>
> ...is interacting somehow. I don't see that you're using it for
> anything anywhere and don't see any reason why you should want to
> requery it for every row of your recordset.
>
> --
> David W. Fenton * * * * * * * * *http://www.dfenton.com/
> contact via website only * *http://www.dfenton.com/DFA/
Hello and thanks for the reply
actually the loop is creating a criteria that i use when i open the
report.
Do Until rptID.EOF
cntrptIDs = cntrptIDs + 1
MsgBox rptID.Fields("ReportID")
strLinkCriteria = strLinkCriteria & " OR " & rptIDField & " =
" & rptID.Fields("ReportID")
notice how the strLinkCriteria is adding to itself.
Me.sfrmutblPrintReportIDs.Requery
rptID.MoveNext
Loop
i actually figured it out, here is the corrected code:
Dim rptName As String
Dim cn As adodb.Connection
Dim rptID As adodb.Recordset
Dim sqlrptID As String
Dim strLinkCriteria As String
Dim rptIDField As String
Dim cntrptIDs As Integer
If IsNull(Me.cboReportType) Then
MsgBox "no report selected"
Me.cboReportType.SetFocus
Exit Sub
End If
Set cn = CurrentProject.Connection
sqlrptID = "SELECT ReportID FROM utblPrintReportIDs ORDER BY
ReportID DESC"
rptName = Me.cboReportType.Column(2)
rptIDField = Me.cboReportType.Column(3)
Set rptID = New adodb.Recordset
With rptID
Set .ActiveConnection = cn
.Source = sqlrptID
.LockType = adLockReadOnly
.CursorType = adOpenForwardOnly
.Open
End With
Application.SetOption "Confirm Action Queries", 0
cntrptIDs = 0
rptID.MoveFirst
Do Until rptID.EOF
cntrptIDs = cntrptIDs + 1
strLinkCriteria = strLinkCriteria & " OR " & rptIDField & " =
" & rptID.Fields("ReportID")
rptID.MoveNext
Loop
strLinkCriteria = Right(strLinkCriteria, Len(strLinkCriteria) - 4)
DoCmd.OpenReport rptName, acViewNormal, , strLinkCriteria,
acNormal, "Print"
'kill everything
rptID.Close
cn.Close
Set cn = Nothing
Set rptID = Nothing
End Sub
the requery you were wondering about is a form and yeah it was legacy
code. i used to delete the list as i printed it, now i dont want to do
that so it is gone.