Call Subform2 from Subform1 on Main form.

G

Guest

Hi,

I have a main form that has two subforms. I am trying to change the record
source of Subform2 on the OnCurrent Event of Subform1 .
I get a run-time error 2455 - You entered an expression that has an invalid
reference to the property Form/Report.
I have tried:

Me.Parent.Form.Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = " &
Me.ID
Me.Parent.Form.Subform2.Form.RecordSouce = "SELECT * FROM TABLE1 WHERE ID =
" & Me.ID
Me.Parent.Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = " & Me.ID
Me.Parent.Subform2.Form.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = " &
Me.ID
Me.Parent!Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = " & Me.ID
Me.Parent!Subform2.Form.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = " &
Me.ID

It seems that the syntax would be easy but I am really stuck on this. What
I would like to do is set the record source and refresh Subform2.
Any suggestions?


Thanks.
 
S

Sandra Daigle

If this is an exact copy of your code you have simply misspelled
RecordSource (you have "RecordSouce").

Otherwise this should work:

Me.Parent.Subform2.Form.RecordSource = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID
 
G

Guest

Hi Sandra,

I typed in all the different cases I have tried. I have been using
RecordSource and not "RecordSouce." I double checked my code and the syntax
is correct. Have been looking online for awhile and can not find a solution.
One thing I noticed is that when I get the error message, and instead of
click the debug button I click on end, and if I go back to the form and
continue triggering the OnCurrent Event of Subform1 it starts to work. This
is wierd.



Sandra Daigle said:
If this is an exact copy of your code you have simply misspelled
RecordSource (you have "RecordSouce").

Otherwise this should work:

Me.Parent.Subform2.Form.RecordSource = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hi,

I have a main form that has two subforms. I am trying to change the
record source of Subform2 on the OnCurrent Event of Subform1 .
I get a run-time error 2455 - You entered an expression that has an
invalid reference to the property Form/Report.
I have tried:

Me.Parent.Form.Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID
= " & Me.ID
Me.Parent.Form.Subform2.Form.RecordSouce = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID
Me.Parent.Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = "
& Me.ID Me.Parent.Subform2.Form.RecordSouce = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID
Me.Parent!Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = "
& Me.ID Me.Parent!Subform2.Form.RecordSouce = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID

It seems that the syntax would be easy but I am really stuck on this.
What I would like to do is set the record source and refresh Subform2.
Any suggestions?


Thanks.
 
G

George Nicholson

Do you only get this error when first opening or closing a form? If so, it
may simply be a timing issue: the subform control hasn't been filled with a
form yet (or the form has already been closed). I haven't run into this
problem for a while, but if, as you say, you can continue running your code
without any apparent problems, you may be able to let your error handler
safely ignore 2455 errors.

Not a particularly elegant solution, granted. One alternative might be to
check for the presence of a form in the subform control before you try to
change it's recordsource. A "IsSubformLoaded()" function, or it's cousin,
"WaitUntilLoaded" ...

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Juan said:
Hi Sandra,

I typed in all the different cases I have tried. I have been using
RecordSource and not "RecordSouce." I double checked my code and the
syntax
is correct. Have been looking online for awhile and can not find a
solution.
One thing I noticed is that when I get the error message, and instead of
click the debug button I click on end, and if I go back to the form and
continue triggering the OnCurrent Event of Subform1 it starts to work.
This
is wierd.



Sandra Daigle said:
If this is an exact copy of your code you have simply misspelled
RecordSource (you have "RecordSouce").

Otherwise this should work:

Me.Parent.Subform2.Form.RecordSource = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID

--
Sandra Daigle [Microsoft Access MVP]
Please post all replies to the newsgroup.

Hi,

I have a main form that has two subforms. I am trying to change the
record source of Subform2 on the OnCurrent Event of Subform1 .
I get a run-time error 2455 - You entered an expression that has an
invalid reference to the property Form/Report.
I have tried:

Me.Parent.Form.Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID
= " & Me.ID
Me.Parent.Form.Subform2.Form.RecordSouce = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID
Me.Parent.Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = "
& Me.ID Me.Parent.Subform2.Form.RecordSouce = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID
Me.Parent!Subform2.RecordSouce = "SELECT * FROM TABLE1 WHERE ID = "
& Me.ID Me.Parent!Subform2.Form.RecordSouce = "SELECT * FROM TABLE1
WHERE ID = " & Me.ID

It seems that the syntax would be easy but I am really stuck on this.
What I would like to do is set the record source and refresh Subform2.
Any suggestions?


Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top