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!

generate a report based on a form and a subform

Status
Not open for further replies.

zxmax

Technical User
Nov 24, 2003
179
CA
This is a second time i post, since i had no replies on my first post, (sorry)

I have a Form with subform , In my subform i have a Print option, that allow me to print a report ,

My problem is, every time run that report, it shows all the records, of the database for that subform ,
i would like it to print only the current Record, (according to the UserID

Eg:

In my main form, i have "UserID" , "firstName" , "LastName", "PhoneNumber"
In my subform , i have some transaction related to the main form, so when i hit print, it should only print only FirstName, LastName, and the transaction in the subform, not all the transactions of the whole database


I was advised to use this
dim strWhere as string

strWhere="Ref=" & forms!myform!reffield
docmd.openreport "ReportName",asviewpreview,strWhere

I'm not sure how to use these info, ? what is the ref= ? and reffield is ?


Thanks for any input, or if you have any other solutions please advise

Thanks alot
 
xzmax
From your post, it appears that you want to print the particular record you are working with at the moment, and only that record.

See if this helps you. It's from an Invoice form, where the invoice details are in in a subform.

I have a query that checks the invoices. One of the columns is the InvoiceNbr. In the Criteria for that column I put [Forms]![frmServiceOrder]![InvoiceNbr]

In the command button on the Invoice form, I put the following code behind a command button...
Private Sub cmdPreviewInvoiceFilter_Click()
On Error GoTo Err_cmdPreviewInvoiceFilter_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim stDocName As String

stDocName = "rptInvoice"
DoCmd.OpenReport stDocName, acPreview, "qryInvoiceFilter"

Exit_cmdPreviewInvoiceFilter_Click:
Exit Sub

Err_cmdPreviewInvoiceFilter_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewInvoiceFilter_Click

End Sub

As you will note, this code saves the record before printing it, and will print the Invoice I am looking at.

Change the names to match your own form and see if you can get it to work. At least, it might be a push in the right direction.
Tom
 
Thanks THWatson

I did follow these steps,

Now i keep getting an message, "Enter Parameter Value" where i put the Current Record ID (in your example it would be InvoiceNbr) ,, if i enter the ID #, it works fine, but i would like to have it to enter the Current ID automatically,

Is there anything im' missing,



 
zxmax
Well, actually, I have two queries.
One query pulls all the data for all customers and invoices.

Then I have a second query with only 2 columns.
One column uses * to pull everything from the first query.
The second column is the InvoiceNbr from the first query, with the criteria [Forms]![frmInvoice]![InvoiceNbr] (you don't need to show the results for this second column as it's used only for criteria)

You might be able to do it all in one query. You'd have to try it.

Not sure why you are being prompted for the paramater twice.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top