By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,644 Members | 1,866 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,644 IT Pros & Developers. It's quick & easy.

subform.form reference problems (A97)

P: n/a
I think at various times we've all encountered this problem:

A subform is on a main form. From the code of the main form we refer
to some property of/control on the child form thus:

Me!subForm.Form!txtTextBox

and for some reason, in certain contexts, we get the error:

Error 2455: You entered an expression that has an invalid reference
to the property Form/Report. The property may not exist or may not
apply to the object you specified.

In my present circumstance, it's a form that's been in operation
without problems since 1997 and it's still in use in A97. The
subform is referred to as above in many contexts from the form.

Tonight I was adding some filtering to the form. The code was called
after the form and its subform had been fully initialized. The code
that was called was:

If Me.RecordsetClone.RecordCount = 0 Then
intSoldFile = 3
Me!subSold.Form!optSold = intSoldFile ' this line errors out
Me.Requery
End If

The variable intSoldFile is a global variable (as I said, this app
dates from 1997, and I would not do it this way these days!) and is
used in the WHERE clause of the main form's recordsource using a
function that returns a usable value based on the global variable
intSoldFile. The control referred to in the subform is the option
group that a user can use to change the value of the variable
intSoldFile and changing the option group's value requeries the
parent form (I can't recall at this point exactly why this is on a
subform and not on the main form; that logic is lost in the fog of 9
years of continual development; I suspect it was move to a subfor in
an effort to solve some kind of problem; whether it was successful
or not I can't say). I'm updating the option group to reflect the
changed value of the global variable.

Now, if I reorder the code as this:

If Me.RecordsetClone.RecordCount = 0 Then
intSoldFile = 3
Me.Requery
Me!subSold.Form!optSold = intSoldFile ' no errors now
End If

the code works just fine.

Now, the function that returns the value for intSoldFile that is
used in the recordsource is actually quite complicated. Here it is
(and this may be a complete red herring):

Public Function getSold() As Variant
On Error GoTo errHandler
If intSoldFile = 0 Or intSoldFile < -1 Or intSoldFile 3 Then
If IsLoaded("frmInventory") Then
intSoldFile = Forms!frmInventory!optSold
Else
intSoldFile = 1
End If
End If

exitRoutine:
Select Case intSoldFile
Case 3
getSold = "*"
Case Else
getSold = intSoldFile - 2
End Select
Exit Function

setValue:
intSoldFile = 1
GoTo exitRoutine

errHandler:
Application.Echo True
MsgBox Err.Number & ": " & Err.Description, vbExclamation, _
"Error in mdlWB.getSold()"
Resume setValue
End Function

Oh, boy, would I write that differently today, but it's been working
for almost 10 years, so I'm not going to dink with working code.

Note that if the value of intSoldFile is not valid (i.e., not 0, -1
or 3) then it gets set based on the value in the form from which I'm
calling this. That is a circular problem.

But it can't be the issue here, as I'm setting intSoldFile to a
valid value (3, which means sold and unsold) before requerying or
setting the option group.

Can anyone figure out why the subform reference works after the
requery but not before it?

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Aug 20 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"David W. Fenton" <XX*******@dfenton.com.invalidwrote in
news:Xn**********************************@127.0.0. 1:
I think at various times we've all encountered this problem:

A subform is on a main form. From the code of the main form we
refer to some property of/control on the child form thus:

Me!subForm.Form!txtTextBox

and for some reason, in certain contexts, we get the error:

Error 2455: You entered an expression that has an invalid
reference to the property Form/Report. The property may not
exist or may not apply to the object you specified.

In my present circumstance, it's a form that's been in
operation without problems since 1997 and it's still in use in
A97. The subform is referred to as above in many contexts from
the form.

Tonight I was adding some filtering to the form. The code was
called after the form and its subform had been fully
initialized. The code that was called was:

If Me.RecordsetClone.RecordCount = 0 Then
intSoldFile = 3
Me!subSold.Form!optSold = intSoldFile ' this line errors
out Me.Requery
End If

The variable intSoldFile is a global variable (as I said, this
app dates from 1997, and I would not do it this way these
days!) and is used in the WHERE clause of the main form's
recordsource using a function that returns a usable value
based on the global variable intSoldFile. The control referred
to in the subform is the option group that a user can use to
change the value of the variable intSoldFile and changing the
option group's value requeries the parent form (I can't recall
at this point exactly why this is on a subform and not on the
main form; that logic is lost in the fog of 9 years of
continual development; I suspect it was move to a subfor in
an effort to solve some kind of problem; whether it was
successful or not I can't say). I'm updating the option group
to reflect the changed value of the global variable.

Now, if I reorder the code as this:

If Me.RecordsetClone.RecordCount = 0 Then
intSoldFile = 3
Me.Requery
Me!subSold.Form!optSold = intSoldFile ' no errors now
End If

the code works just fine.

Now, the function that returns the value for intSoldFile that
is used in the recordsource is actually quite complicated.
Here it is (and this may be a complete red herring):

Public Function getSold() As Variant
On Error GoTo errHandler
If intSoldFile = 0 Or intSoldFile < -1 Or intSoldFile 3
Then
If IsLoaded("frmInventory") Then
intSoldFile = Forms!frmInventory!optSold
Else
intSoldFile = 1
End If
End If

exitRoutine:
Select Case intSoldFile
Case 3
getSold = "*"
Case Else
getSold = intSoldFile - 2
End Select
Exit Function

setValue:
intSoldFile = 1
GoTo exitRoutine

errHandler:
Application.Echo True
MsgBox Err.Number & ": " & Err.Description, vbExclamation, _
"Error in mdlWB.getSold()"
Resume setValue
End Function

Oh, boy, would I write that differently today, but it's been
working for almost 10 years, so I'm not going to dink with
working code.

Note that if the value of intSoldFile is not valid (i.e., not
0, -1 or 3) then it gets set based on the value in the form
from which I'm calling this. That is a circular problem.

But it can't be the issue here, as I'm setting intSoldFile to
a valid value (3, which means sold and unsold) before
requerying or setting the option group.

Can anyone figure out why the subform reference works after
the requery but not before it?
I've seen cases, mostly on subforms, but sometimes on bound
forms, where Access gets messed up if it cannot find the
control, due to the fact that the detail section of the form is
not rendered, there being no records in the set and the
AllowAdditions property is false.

In your case, the requery gets at least 1 row.

--
Bob Quintal

PA is y I've altered my email address.

--
Posted via a free Usenet account from http://www.teranews.com

Aug 20 '06 #2

P: n/a
Bob Quintal <rq******@sPAmpatico.cawrote in
news:Xn**********************@66.150.105.47:
I've seen cases, mostly on subforms, but sometimes on bound
forms, where Access gets messed up if it cannot find the
control, due to the fact that the detail section of the form is
not rendered, there being no records in the set and the
AllowAdditions property is false.

In your case, the requery gets at least 1 row.
OK, that would be it, wouldn't it! There is no record, so none of
the controls are loaded, which was the point of changing the global
variable to broaden the resultset.

Thanks. I don't know why I couldn't see that.

--
David W. Fenton http://www.dfenton.com/
usenet at dfenton dot com http://www.dfenton.com/DFA/
Aug 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.