Putting current data in a report

Robert C

Registered User.
Local time
Today, 11:38
Joined
Mar 27, 2000
Messages
88
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.
 
Hello Robert,

I think the only problem with your code is the line:
"[OrderDetailID]=forms!frmOrders![sbfOrderDetails]![OrderDetailID]"
I reckon you may have the last quote in the wrong place and it should read:
"[OrderDetailID]=" & forms!frmOrders![sbfOrderDetails]![OrderDetailID]
Hope that gets you there.
Regards
Robin.
 
Robin

Thanks for the reply. I'm afraid it didn't work. The quote marks are in this position in the other instances in which I use this code and it works fine there. I'm completely stumped. Thanks again anyway.
 
Hello Again Robert,

I must say I feel pretty dumb at this stage, I just woke up that you are calling a value from a sub form (I think) so the only thing wrong is: "[OrderDetailID]=" & forms!frmOrders![sbfOrderDetails]![OrderDetailID] should read: "OrderDetailID=" & forms!frmOrders!sbfOrderDetails.Form.OrderDetailID I removed the square brackets 'cause you don't need them to refer to a text box only for a field.

Hope this one works, if not, send me a copy of the database and I'll see what I can do.

Regards
Robin.
 
Hi Robin

Thanks very much it all works fine now - except its very slow - see my other posting.

Don't suppose you've got any clues about this?

Cheers

Rob
 

Users who are viewing this thread

Back
Top Bottom