Hi,
I was wondering if anyone might be able to help me.
I have a form and it has listbox displaying a certain number of records and it also has a button "Print All". What this button does is it would print to the report whatever on the listbox. My question here is because i'd like to let user be able to choose printer/page setup, so i run the command acCmdPrint. My problem is i like the printer windows to come up first as soon as the button is hit. And if the user hit "cancel", it would stop printing all the records on. It'd only print if the user click "print".
Private Sub CM_PrintList_Click()
On Error Resume Next
Dim rsNew As New ADODB.Recordset
Dim myFO_ID_1, myFO_ID_2 As String
nList = Me.LB_PrintSelection.ListCount
Mtext = "Ready to print" + Str$(nList) + " documents"
If MsgBox(Mtext, 49, "Outline Report Printing") = 1 Then
DoCmd.SelectObject acReport, stDocName
DoCmd.RunCommand acCmdPrint
If Err.Number <> 0 And Err.Number <> 2501 Then
MsgBox Err.Number & ":" & Err.Description, vbCritical
Else
Err.Clear
End If
For nCount = 0 To nList - 1
Me.TB_PSselect = Me.LB_PrintSelection.ItemData(nCount)
'stLinkCriteria = "[FO_ID]=" & Chr$(34) & Me.LB_PrintSelection.ItemData(nCount) & Chr$(34) 'Set Filter
DoEvents
stDocName = "Outline Report"
myFO_ID_1 = Me.LB_PrintSelection.ItemData(nCount)
rsNew.Open "Select * from [Framework Outline]", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until rsNew.EOF
If rsNew!FO_ID = myFO_ID_1 Then
If rsNew!Structure <> "P" Then
myFO_ID_2 = rsNew!Structure
ElseIf rsNew!Structure = "P" Then
myFO_ID_2 = myFO_ID_1
End If
Exit Do
End If
rsNew.MoveNext
Loop
rsNew.Close
stLinkCriteria = "[FO_ID]=" & Chr$(34) & myFO_ID_2 & Chr$(34) 'Set Filter
Me.TB_test = myFO_ID_1
DoCmd.OpenReport stDocName, acViewPreview
DoCmd.Close acReport, stDocName, acSaveNo 'Refresh Report
DoCmd.OpenReport stDocName, , , stLinkCriteria
'DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
DoEvents
DoCmd.Close acReport, stDocName
'Beep
Next nCount
End If
End Sub
I tried to run the acCmdPrint at the start just before the For loop, i couldn't stop it from going into the for loop after clicking "cancel" button on the print popup windows.
Your help is greatly appreciated. Thank you in advance
I was wondering if anyone might be able to help me.
I have a form and it has listbox displaying a certain number of records and it also has a button "Print All". What this button does is it would print to the report whatever on the listbox. My question here is because i'd like to let user be able to choose printer/page setup, so i run the command acCmdPrint. My problem is i like the printer windows to come up first as soon as the button is hit. And if the user hit "cancel", it would stop printing all the records on. It'd only print if the user click "print".
Private Sub CM_PrintList_Click()
On Error Resume Next
Dim rsNew As New ADODB.Recordset
Dim myFO_ID_1, myFO_ID_2 As String
nList = Me.LB_PrintSelection.ListCount
Mtext = "Ready to print" + Str$(nList) + " documents"
If MsgBox(Mtext, 49, "Outline Report Printing") = 1 Then
DoCmd.SelectObject acReport, stDocName
DoCmd.RunCommand acCmdPrint
If Err.Number <> 0 And Err.Number <> 2501 Then
MsgBox Err.Number & ":" & Err.Description, vbCritical
Else
Err.Clear
End If
For nCount = 0 To nList - 1
Me.TB_PSselect = Me.LB_PrintSelection.ItemData(nCount)
'stLinkCriteria = "[FO_ID]=" & Chr$(34) & Me.LB_PrintSelection.ItemData(nCount) & Chr$(34) 'Set Filter
DoEvents
stDocName = "Outline Report"
myFO_ID_1 = Me.LB_PrintSelection.ItemData(nCount)
rsNew.Open "Select * from [Framework Outline]", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Do Until rsNew.EOF
If rsNew!FO_ID = myFO_ID_1 Then
If rsNew!Structure <> "P" Then
myFO_ID_2 = rsNew!Structure
ElseIf rsNew!Structure = "P" Then
myFO_ID_2 = myFO_ID_1
End If
Exit Do
End If
rsNew.MoveNext
Loop
rsNew.Close
stLinkCriteria = "[FO_ID]=" & Chr$(34) & myFO_ID_2 & Chr$(34) 'Set Filter
Me.TB_test = myFO_ID_1
DoCmd.OpenReport stDocName, acViewPreview
DoCmd.Close acReport, stDocName, acSaveNo 'Refresh Report
DoCmd.OpenReport stDocName, , , stLinkCriteria
'DoCmd.OpenReport stDocName, acViewPreview, , stLinkCriteria
DoEvents
DoCmd.Close acReport, stDocName
'Beep
Next nCount
End If
End Sub
I tried to run the acCmdPrint at the start just before the For loop, i couldn't stop it from going into the for loop after clicking "cancel" button on the print popup windows.
Your help is greatly appreciated. Thank you in advance