Passing data from a Form to a Report

daveUK

Registered User.
Local time
Today, 09:51
Joined
Jan 2, 2002
Messages
234
I'm not too sure whether this problem will come under forms or reports but I'll post it here anyway
biggrin.gif

I need to pass the contents of a textbox on a form to a textbox on a report. I know how to pass data between forms using the OpenArgs method, and I thought this would be the same for a report. Unfortunately Access doesn't seem to like it.

I have the following code under the command button on the form that opens up the report.

Private Sub cmdPrint_Click()
DoCmd.OpenReport "RptPrint", acViewPreview, , Me!Location
End Sub

Location is the name of the textbox on the form. When Access tries to open up the report, it displays an error. I have the following code underneath the report.

Me!txtLocation = Me.OpenArgs

txtLocation is the textbox on the report. Access highlights the 'OpenArgs' and gives the error "Method or Data not found".

I know this code works with forms, why not with reports?

Any ideas??

Dave
 
Forms and Reports are completely different things - even though they do have quite a bit in common. I agree with you that having an OpenArgs property in a report would be very useful. However as there isn't, here are a few other ideas.

Reference the text box explicitly within the query (or SQL string) on which the form is based (i.e. include something like "WHERE Location = Forms!FormName!Location.

You can open a report with a "where condition", like this:

DoCmd.OpenReport "rptPrint", acViewPreview, , "Location = " & Me!Location

or, if location is a string

DoCmd.OpenReport "rptPrint", acViewPreview, , "Location = """ & Me!Location & """"

Simon
 
SimonC

Thanks for the reply, it's when the report actually opens that the error occurs. The code underneath the cmd button on the form

DoCmd.OpenReport "RptPrint", acViewPreview, , Me!Location

works OK. The error is with the code on the Open/load/activate of the report.

Me!txtLocation = Me.OpenArgs

Access highlights the .OpenArgs part and a msgbox states, "Method or Data not found"

Any ideas?

Dave
 
Providing the form is open when the report opens then just set the control source of the control on the report to =Forms!SomeForm!SomeField
HTH
 
Rich

Access didn't seem to like your code but
I've managed to get the details passed from the form to the report by using the following on the record source of the report

SELECT tblPhoto.Location FROM tblPhoto

But this displays ALL of the records and not just the one the user is viewing.
 
Hi there,

I know this is an old thread but it is similar to what I am looking to ask so I thought it made sense to start from something.

I have a reports front end which is simply a listbox containing a list of reports. I have set a condition whereby on clicking on certain reports, a pop form prompts the user to enter two dates and these dates transfer to the start and end date textboxes on particular reports.

This is fine and would work ok to get the date as a static field across but what about filtering the report data according to the date range?

The main report which has this pop function is built up from a number of sub reports and queries so I would rather not have to go through each of these to set a date criteria. Not only that, this report can be accessed in other ways so it needs to be kept flexible.

Any ideas?
 

Users who are viewing this thread

Back
Top Bottom