referencing mainform control from another form

Peter Griffin
Peter Griffin used Ask the Experts™
on
I have a mainform.  From the mainform I open a reportform that has buttons to open different reports based on the selected record in the mainform.  One of the reports is merely a structured report showing the selected record.  This is mainly what is showing on the mainform is then put into controls (txtboxes) on the report.  This is done by clicking a button on the reportform.  What I am running into is an error that indicates cannot find the form.  Below is one of the lines for the button.  It is the frmLocation (mainform) that is being mentioned in the error message.  Even tried  Forms!frmLocation.Form!txtLocationName and still got the same error.

Reports!rptLocationFullReport.Report!txtLocationName = Forms!frmLocation!txtLocationName

Anyone have any suggestions?

Thanks ... John
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dale FyeOwner, Dev-Soln LLC
Most Valuable Expert 2014
Top Expert 2010

Commented:
Well, unless you have a subreport embedded in rptLocationFullReport, I think the syntax you are looking for is something like:

me.txtLocationName = forms!frmLocation.txtLocationName

Where me represents whatever report is opened and assumes that there is a control on that report with the same name as the control on frmLocation.

Question:  Why isn't your report bound to the same recordset as your main form?

HTH
Dale
The frmLocation (mainform) is actually an unbound form that has a listbox on it with all the locations.  Select a location and the rest of the form displays the information.  So, the frmLocation holds the info I need.  There is a button on frmLocation that opens a small form (frmLocationReport) that has all the buttons on it for reports associated with only the displayed location on frmLocation.  You could think of this as a triangle.  Need all 3 points to make it work; frmLocation for the displayed location, rptLocationFullReport to save as a pdf report, and frmLocationReport a small form to have all the buttons for the different reports for frmLocation.  The objective is to populate a report based on the information seen on the form.  

Thanks for the response.

... John
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and Programming
Top Expert 2015

Commented:
>> What I am running into is an error that indicates cannot find the form. <<
the form must be open and not in design view

in the report Open event, which can be cancelled, do:
if  SysCmd(acSysCmdGetObjectState, acForm, "MyMainFormName")  = 0 then
   MsgBox "Form must be open to run the report",,"Cancelling Report"  'or whatever you want to say
   Cancel = true
   Exit sub
end if

Open in new window

this will send an error to the calling code for OpenReport so either handle the error, or put this right before the OpenReport statement:
On Error resume next

Open in new window

As Dale suggested, make the assignments in the code behind the report. If anything required is not filled, cancel the report. This could all be done in the Open event.

>> The objective is to populate a report based on the information seen on the form.   <<
is the unbound information going to be stored?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial