I hope someone can help me. I am trying to put some code behind a command button to tell access to print the current record as a report called rptPuchaseOrder. I have done this successfully on other forms in my database but in this instance the report prints out with no data whatsoever. I am mystified. The only difference between this and the other instances is that I've introduced the message boxes - which both work fine. The main form is called frmOrders and it has a subform called sbfOrderDetails which is derived from a form called frmOrderDetails.
The code I currently have is as follows:-
Private Sub btnPrintOrder_Click()
On Error GoTo Err_btnPrintOrder_Click
Dim stDocName As String
stDocName = "rptPurchaseOrder"
If IsNull(Me.[ProjectID]) Then
MsgBox "Sorry, but you can't print this order until you've selected a Project from the list."
Me.[cboProjectName].SetFocus
Exit Sub
ElseIf IsNull(Me.[OrderedBy]) Then
MsgBox "Sorry, but you can't print this order until you've entered a name from the 'Ordered By' list."
Me.cboOrderedBy.SetFocus
Exit Sub
Else
DoCmd.OpenReport stDocName, acViewPreview, , "[OrderDetailID]=forms!frmOrders![sbfOrderDetails]![OrderDetailID]"
End If
Exit_btnPrintOrder_Click:
Exit Sub
Err_btnPrintOrder_Click:
MsgBox Err.Description
Resume Exit_btnPrintOrder_Click
End Sub
Any help on this would be greatly appreciated. Thanks.
The code I currently have is as follows:-
Private Sub btnPrintOrder_Click()
On Error GoTo Err_btnPrintOrder_Click
Dim stDocName As String
stDocName = "rptPurchaseOrder"
If IsNull(Me.[ProjectID]) Then
MsgBox "Sorry, but you can't print this order until you've selected a Project from the list."
Me.[cboProjectName].SetFocus
Exit Sub
ElseIf IsNull(Me.[OrderedBy]) Then
MsgBox "Sorry, but you can't print this order until you've entered a name from the 'Ordered By' list."
Me.cboOrderedBy.SetFocus
Exit Sub
Else
DoCmd.OpenReport stDocName, acViewPreview, , "[OrderDetailID]=forms!frmOrders![sbfOrderDetails]![OrderDetailID]"
End If
Exit_btnPrintOrder_Click:
Exit Sub
Err_btnPrintOrder_Click:
MsgBox Err.Description
Resume Exit_btnPrintOrder_Click
End Sub
Any help on this would be greatly appreciated. Thanks.