changing the recordsource property

  • Thread starter Thread starter Eric
  • Start date Start date
E

Eric

I'm trying to change the recordsource property for a form
before I open it. I seem to only be able to do it with
the following code:

Me.RecordSource = "43Parts"

These ways suggested by MS Help do not seem to work:

Method 1:
DoCmd.OpenForm [Estimating Parts Subform]
Forms![Estimating Parts Subform].RecordSource = "43Parts"
DoCmd.Close
<code executes but doesn't change the RecordSource>

Method 2:
Dim frm as New [Estimating Parts Subform]
frm.RecordSource = "43Parts"
<first line doesn't compile>
 
Eric said:
I'm trying to change the recordsource property for a form
before I open it. I seem to only be able to do it with
the following code:

Me.RecordSource = "43Parts"

These ways suggested by MS Help do not seem to work:

Method 1:
DoCmd.OpenForm [Estimating Parts Subform]
Forms![Estimating Parts Subform].RecordSource = "43Parts"
DoCmd.Close
<code executes but doesn't change the RecordSource>

Method 2:
Dim frm as New [Estimating Parts Subform]
frm.RecordSource = "43Parts"
<first line doesn't compile>

Is it a form, or is it -- as its name implies -- a subform that is
actually being displayed on another form? It makes a difference. Your
first example, method 1, should work, but only if the form is a main
form, not a subform. Method 2 is not quite right -- it should be "Dim
frm as New Form_Estimating_Parts_Subform" -- and, even if corrected,
will only work if the form is a main form *and* has a class module.

If you're trying to change the recordsource of a subform on a main form,
then one of the following should work, with provisos as stated:

(1) If the code is executed on the main form, and "Estimating Parts
Subform" is the name of the subform control that displays the subform,
not just the name of the form object being displayed by that control,
then this should work:

Me![Estimating Parts Subform].Form.RecordSource = "43Parts"

(2) If the code is executing from outside of the main form, then the
same provisions apply, but also we need to know the name of the main
form. Supposing that form to be named "MainForm", then this should
work:

Forms!MainForm![Estimating Parts Subform].Form.RecordSource =
"43Parts"


Note that the above example code lines were each entered as one line,
but may have been wrapped to two by the newsreader.
 
Back
Top