[AccessD] Open Report from MainForm based on SubForm

Charlotte Foust cfoust at infostatsystems.com
Wed Oct 14 10:12:21 CDT 2009


You could make life easier by giving controls a different name from the
field they're bound to.  That would also reduce the incidence of this
kind of error.  Name your textbox txtVehicleInspID on the form and
change the code appropriately.  See whether that produces an error.  You
can get this kind of thing when Access can't figure out WHICH
VehicleInspID you're referring to.  The fact that it says  "Can't find
field VehicleInspID" says that it's looking for a field when it should
be looking for a control.  

Charlotte Foust

-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Hollis,
Virginia
Sent: Wednesday, October 14, 2009 7:58 AM
To: accessd at databaseadvisors.com
Subject: Re: [AccessD] Open Report from MainForm based on SubForm

*         Form: frm_VehicleInspection

*         Subform: frm_VehicleInspectionSub

*         Report: rpt_VehicleInspection

*         Textbox on subform: Control source- VehicleInspID

*         Name of textbox on subform: VehicleInspID

*         Textbox on Report: Control source- VehicleInspID

*         Name of textbox on Report: VehicleInspID

Error: Microsoft Access can't find the field VehicleInspID referred to
in your expression.

 

stDocName = "rpt_VehicleInspection"

    Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].SetFocus

    DoCmd.OpenReport stDocName, acViewPreview, , "VehicleInspID=" &
"Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].Form![VehicleI
nspID]=" & Me![VehicleInspID]

 

*****

 

 

What is this field called in the data source of the report you are

opening?  It needs to match that.  It might be FKxyzID in the Form but

be called xyzID in the Report.  They need to match.

 

What is the error that is coming up.?

 

max

 





 

You have it all named correctly. I changed "MyRpt" is all I had to
change.

**********

you have to put in YOUR OWN names/values. I do not know what you call

it.  I was showing the syntax and format.

 

max

 

Subject: [AccessD] Open Report from MainForm based on SubForm

 

I checked and the subform is named correctly (frm_VehicleInspectionSub).
The first part of the code sets the focus to the subform & this works.

 

With your example I get - "Can't find field VehicleInspID referred to in
your expression". I checked the names & the control sources and they all
show VehicleInspID;

********

The syntax you want is:-
 
DoCmd.OpenReport "MyRpt", acViewPreview, , "VehicleInspID=" &
"Forms![frm_VehicleInspection]![frm_VehicleInspectionSub].Form![VehicleI
nspID]="
& me![VehicleInspID]
 
Virginia, make SURE that your have the correct NAME of the sub form.
Often people think they know what it is called but it isnt called that
at all.  Check the data AND "Other" Tab in the properties.
 
I have a sub form where the DataSource = "MCM_PeoplePopNAD" But I call
the form (Under the Other Tab in the properties) "PeoplePopSub2"
 
Max
 
--
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list