Printing a specific report based on form that is on screen

G

Guest

I am having the worst time figuring out what I'm doing wrong. I have a form that works very well and need to print a report based on the form that is showing. I have tried the examples I've seen here and used the wizard but I can't get it to work. It always goes back to the first record no matter what form is showing. The following is the code I have to preview the report. When I test values in the report code the current form values are there but don't get used when the preview window opens

Private Sub preview_Click(
On Error GoTo Err_preview_Clic
Dim stDocName As Strin

DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70 'refres
DoCmd.Minimize ' minimizes the for
stDocName = "rptWSWD
DoCmd.OpenReport stDocName, acPreview, , "rReportNoID = " & Me!fReportNoI

Exit_preview_Click
Exit Su
Err_preview_Click
MsgBox Err.Descriptio
Resume Exit_preview_Clic

End Su

This is some of the code I have in the report. Zeronull is a function I have to assign the values 1, 0 or null to unbound textbox controls based on the -1,0 values of a checkbox and text in another control. It works very well in both the form and report
I have the line " Y = ... " to test the value and it gives the value of the form that is showing. As does Wkend have the correct date of the form. But when the report opens it starts at the first record

Private Sub Report_OPEN(Cancel As Integer
Y = Forms![frmWSWD]!fReportNoI
WKend = Forms![frmWSWD]!tWkEndin


For N = 0 To
STR = "=ZeroNull([fWD" & N & "],[tCond" & N & "])
Set CTRL = Controls("uWD" & N
CTRL.ControlSource = STR
Next

Maybe someone can spot what I'm doing wrong or let me know what else I have to add
Thanks
 
J

Jeff Boyce

Rich

If I understand your description (and code), you are opening the report, but
not setting the WHERE (or filter) to the ID of the RECORD -- it looks like
you are setting it to the ID of the REPORT. (but maybe I don't understand
your field naming convention...)
 
G

Guest

Thanks for looking at this Jeff.

The sub - preview_click is in the code for the form named frmWSW
I'm putting the name of the report in

stDocName = "rptWSWD

Every example I've seen had the Filter field blank between commas. The key field should be enough to identify each unique record. rReportID is the name of the control on the report. fReportID is the name on the form and the key field for the form. The record source for the form is a query called qryWSWD which is also the record source for the report
I thought the last part is the WHERE clause for calling the Report based on the specific field.

DoCmd.OpenReport stDocName, acPreview, , "rReportNoID = " & Me!fReportNoI
 
J

Jeff Boyce

Rich

I'm still confused. You mention both a "fReportID" and a "fReportNoID" --
are these the same thing, with two different names?
 
J

Jeff Boyce

Rich

In reading back over this thread, I wonder if the issue might be happening
because you are trying to filter on a control in the report, and are using a
control in the form.

Forgetting the naming convention for a moment, I would approach this as:

"TableID = " & Me!FormControlName

because I want the report to open using the record (from the table, or
query) that has the ID "seen" in the form.
 
G

Guest

Thanks Jeff, I finally got it to work. I used what you said and combined it with something I saw in someone else's question and finally got it. I couldn't have done it without you and it was so darn simple really I can't believe MS doesn't put this in their helps

stWHERE = Chr(34) & Me!fAsstDiaryID & Chr(34)
DoCmd.OpenReport stDocName, acViewPreview, , "[tAsstDiaryID] = " & stWHERE

The chr(34) is equivalent to quotations " These were necessary to surround my ID value because it is text and not a number. Prior to that the program kept asking for the parameter which didn't work either until I used your cod

Thanks again. This solves my problem for the future reports I have to create.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top