Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Forms Programming / March 2005

Tip: Looking for answers? Try searching our database.

Error (2450) when changing a forms recordsource through code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dale Fye - 28 Mar 2005 19:51 GMT
I have a form that displays a bunch of information to the user.  On the form,
I have two command buttons that fire off a series of actions. The last action
in the click event of each of these buttons is to open a form, which contains
a couple of subforms, the difference being the RecordSource for the two
subforms.  When I click one of the buttons, and execute code that looks like
the following, it executes properly.  When I click the other button, I change
the record source for the two subforms, but I get an error indicating that
the form cannot be found.  I have checked to make sure that the code is
identical, only the name of the queries change between the two subroutines.

Private sub Button1_Click

  'do something here
  forms("frm_Report_rollup").RecordSource = "qry_rollup"
  forms("frm_Report_details").RecordSource = "qry_details"
  docmd.openreport "MyReport"

end sub
Brendan Reynolds - 28 Mar 2005 21:28 GMT
Subforms are not members of the Forms collection. You need to refer to them
via their parent form ...

Forms("NameOfParentForm").Controls("NameOfSubformControl").Form.RecordSource

If the code is running from the parent form, you can shorten this to ...

Me!NameOfSubfromControl.Form.RecordSource

Signature

Brendan Reynolds (MVP)

>I have a form that displays a bunch of information to the user.  On the
>form,
[quoted text clipped - 20 lines]
>
> end sub
Dale Fye - 28 Mar 2005 23:39 GMT
Brandan,

At the time of the change in the record source, their parent form has not
yet been loaded.  Plus, I would think I would get the same error, regardless
which of the two buttons I clicked, but I don't.  With one button, the forms
load properly, with the other, I get the error message.  I have not tried
this yet, but now that I think about it, the one that does not generate the
error has the same recordsource as the default for those forms, so maybe it
isn't updating the recordsource in either instance.

> Subforms are not members of the Forms collection. You need to refer to them
> via their parent form ...
[quoted text clipped - 29 lines]
> >
> > end sub
Brendan Reynolds - 29 Mar 2005 09:25 GMT
Subforms, or, to be more specific, forms which are being used as the
SourceObject of a subform control, are not members of the Forms collection,
so if code similar to that which you posted is working, the forms in
question are not being used as subforms in this specific sense - perhaps you
are using the term differently?

Signature

Brendan Reynolds (MVP)

> Brandan,
>
[quoted text clipped - 45 lines]
>> >
>> > end sub
Dale Fye - 30 Mar 2005 02:17 GMT
Brendan,

Got it.  I moved the code for the recordsource to the Open event of the main
form, and passed it a value in the OpenArgs parameter of the the OpenForms
method.

Thanks for the help.

Dale
> Subforms, or, to be more specific, forms which are being used as the
> SourceObject of a subform control, are not members of the Forms
[quoted text clipped - 54 lines]
>>> >
>>> > end sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.