You entered an expression that has an invalid reference to the property Form/Report

N

Nick Stansbury

See this post for background info (similar problem):

http://groups.google.co.uk/group/mi...eport"+subform&rnum=74&hl=en#93801a080cbe4404

I experienced a similar problem to the author of the above post. I
dynamically load the source object for a subform in code. Here is an
example:

Public Sub PopulateSubForm(MySubFormControl As SubForm)
Dim MyRS As ADODB.Recordset, MySubForm As Form, MySubformSourceObject As
String, MyIPname As String
MySubFormControl.SourceObject = "BLAHBLAH"
Set MySubForm = MySubFormControl.Form
'Build a recordset from a call to the remote sql server here....
Set MySubForm.Recordset = MyRs
End Sub

This line of code - [ Set MySubForm = MySubFormControl.Form ] was throwing a
sporadic run time error : "You entered an expression that has an invalid
reference to the property Form/Report"

The error was sporadic. There seemed to be no common factors accross the
various occurences. Most times clicking into the sub form and then
re-populating it would work - but not always. Moving to the next record (as
in the post above) would resolve the problem, sometimes. Decomiple, compact
/ repair, recreate references, revert to back up - none of it helped.
However the following did :

SOLUTION -> Setting the focus to the subform container fixed the problem - I
added "MySubFormControl.SetFocus" immediately after setting the source
object and the problem went away.

Weird. Hope that this post means someone else can spend less time on this
problem than I did.

Nick
 
G

George Nicholson

Just a thought: A "DoEvents" in the same place *might* achieve the same
thing: stall, and give the subform time to fully load before referencing it
(especially if it has a large unfiltered RecordSource in its "natural",
just-opened state).

- or add a "wait until loaded" routine.
- or modify the design of the subform so that it initially opens with a
small & fast recordset (which you will be resetting 2 lines later)

HTH,
 
Joined
Jan 11, 2011
Messages
6
Reaction score
0
I was having the same problem when using 2 subforms in a form. Apparently if you call any form's functions before the form is loaded it will produce this error. The fix was moving the failed subform above the one calling the code.
The load order is subforms first, from top to bottom, followed by the parent form.
 

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