Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a Report using Command button in a Form

Status
Not open for further replies.

jcmv007

Technical User
Nov 1, 2001
88
US
Windows XP
Microsoft Access 2000 (9.0.3821 SR-1)

Working with ms-access I have created a form to place Purchase Orders. I have also create the report to print the Purchase Order. In the Orders form I created a command button that calls the report "Order Document" and it work
almost fine. The problem is that it brings up the report with the FIRST order created an I want it to bring the Order that has just been created. Here is the code used:

Private Sub PreviewInvoice_Click()
Dim LinkFilter As String

On Error GoTo Err_PreviewInvoice_Click
If Forms![Orders]![Order Details Subform].Form.RecordsetClone.RecordCount = 0 Then
MsgBox "Enter order information before previewing order."
Else
'DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
DoCmd.OpenReport "Order Document", acPreview, , "Me![Orders]![OrderID]"
End If

Exit_PreviewInvoice_Click:
Exit Sub

Err_PreviewInvoice_Click:
If Err <> 2501 Then
MsgBox Err.Description
End If
Resume Exit_PreviewInvoice_Click
End Sub

I would appreciate it if the answer includes the sample or corrected code.

Thanks in advance.
 
HI


If Forms![Orders]![Order Details Subform].Form.RecordsetClone.RecordCount = 0 Then
MsgBox &quot;Enter order information before previewing order.&quot;
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport &quot;Order Document&quot;, acPreview, , &quot;Me![Orders]![OrderID]&quot;
End If

Should print the record which is currently visible on the form, having first saved it Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Ken,

I changed the code but when I try it a windows pops up asking for Enter Parameter Value and refers to Me!Orders!OrderID

Any clue on why this is happening.


Thanks,

James

 
Hi

Sorry, I just copied your code, looking for the original problem you reported, but you should not have quotes around the criteria


DoCmd.OpenReport &quot;Order Document&quot;, acPreview, , Me![Orders]![OrderID]
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Ken,

Hello Again. NOw I am getting the following message:

Microsoft Access can't find the field &quot;orders' referred to in your expresiion.

HELP! :)
 
Hi

The problem lies with Me![Orders]![OrderID]

without knowing the detail of your form it is difficult to diagnose the problem but is your form by change called Orders?

so should it be Me![OrderID]
Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Hi

An alternative way to do what you are trying to achieve:

Make the query which drives the report have a critieria of Forms!Order!OrderId and trim the do command down to DoCmd.OpenReport &quot;Order Document&quot;, acPreview Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
UK
 
Hello Again,

Thanks a lot for your help!!! I finaly solve my problem and did it with the following code:

DoCmd.OpenReport &quot;Order Document&quot;, acPreview, , &quot;[Orders_OrderID] = Forms![Orders]![OrderID]&quot;

I the aparent problem was that the OrdersID field was named diferent in the Report.

Thanks,


James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top