473,888 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

subform.form reference problems (A97)

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.RecordsetClo ne.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.RecordsetClo ne.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("frmIn ventory") Then
intSoldFile = Forms!frmInvent ory!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.Ech o 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
2 4296
"David W. Fenton" <XX*******@dfen ton.com.invalid wrote 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.RecordsetClo ne.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.RecordsetClo ne.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("frmIn ventory") Then
intSoldFile = Forms!frmInvent ory!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.Ech o 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
Bob Quintal <rq******@sPAmp atico.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1139
by: pei_world | last post by:
Hi, the problem describes as below: 1st question //============== code =================== //= in Parent Form, I create following function: void newForm(Form parent,Form theForm){ foreach(Form subForm in parent.MdiChildren){ if(subForm.Name == theForm.Name){ subForm.Hide(); subForm.Show();
3
518
by: tlyczko | last post by:
I have a main form with 2 subforms, each subform references different data in the same table. How do I make sure each subform only creates NEW records in the referenced table and do not overwrite or change data in previously created rows?? Otherwise I have to use two different tables, with similar kinds of data, for each subform, which may well be the way to go even though it's not really normalized, to make the data entry easier and...
5
9152
by: Richard J Foster | last post by:
Hi there, I have a pair of C# projects in VS2003. The first project, a dll, is referenced in the second via a project reference. The assemblies in question are delay-signed during a "production" build process, but not as part of a normal development build. I have noticed that while the correctly signed assembly is present in the designated output folder for the project (e.g. bin/Release), an
4
2445
by: godsent | last post by:
hello all. plz help me wid this simple yet complicated prob: how to create a subform form in Ms Access( Visual BAsic)..am not able to start this wizard.. thanks
1
2814
by: jdicko5579 | last post by:
Hello: I am fairly new to Access and was wondering if someone could help me out. I have a main form with header. In the detail section of the main form, there is a subform. The subform has a header and a detail section. I am not able to tab from the last record in the main form's header to the header of the subform. Also, I am not able to tab from the subform's header, to the subform detail section. I have set the tab order for each...
1
4158
by: mark_aok | last post by:
Hi all, I have a form with a subform called "mySubForm" (the subform is always in datasheet view), and I have a button labeled "return item". When users click return item, it finds the record from the datasheet, and it modifies some fields. The problem is, I am randomly getting an error saying "no current record". When I check me.mySubForm.form.currentRecord, it shows a perfectly valid
1
13803
by: ramaswamynanda | last post by:
Hello, I am working on an application in MS Access. I have an employee form with an employee charges subform. the subform is supposed to be displayed in the datasheet view. I have put the labels for column headers in the form header, and the charges total in the form footer. What happens is , the header and footer are visible both on the subform and the parent form in design view, but neither appears in run mode. I have gone through every...
11
7044
by: thatguyNYC | last post by:
This is a complicated one... I have a modal form that lets the user preview some text, then either click Submit or Close. This form is called from several other forms. What I would like, since Access can't return a value from a form, is to set (from the modal form) a hidden checkbox on the calling form, which would show which button the user pressed on the modal form. My problem is this -- how can I pass the name of the calling form...
1
8385
by: dohminator | last post by:
Hello Experts, I have two systems written in Access 2003 that I'm in the process of merging. A user will be given a specific screen depending on his user name. I have a form (let's call it frmPMain) that I'd like to use as a stand-alone filter but I'd also like it to be a subform of another form (frmWMain). My question is this - In SQL Query Builder is there a way that I can reference a field's parent form without an implicit reference...
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9597
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5819
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.