473,725 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with subreport referencing

Hmmm, I'm not too good with the syntax of referencing a subreport.

I have frmInvoice which has the invoice details (e.g. ProductCode,
ProductCost etc) in the subform frmInvoiceDetai ls. I'm trying to get a field
(AccountID) to show in the parent form based on whether a particular product
code (EXT) is present in the list of ProductCodes on the subform. So far
I've tried:

IIf(Reports![frmInvoiceDetai ls]![ProductCode]="EXT",Null,[Reports![frmInvoic
e]![AccountID])

But I get an error. Any ideas would be appreciated,

thanks

Alan
May 10 '06 #1
9 7361
"Alan" <no****@nospam. com> wrote
Hmmm, I'm not too good with the syntax of referencing a subreport.

I have frmInvoice which has the invoice details (e.g. ProductCode,
ProductCost etc) in the subform frmInvoiceDetai ls. I'm trying to get a
field
(AccountID) to show in the parent form based on whether a particular
product
code (EXT) is present in the list of ProductCodes on the subform. So far
I've tried:

IIf(Reports![frmInvoiceDetai ls]![ProductCode]="EXT",Null,[Reports![frmInvoic
e]![AccountID])

But I get an error. Any ideas would be appreciated,


A Form embedded in a Subform Control, even if visible is not "Open" and,
thus, not in the Forms Collection. It exists as the Form property of the
Subform Control. In code in the Form's module of the main form, you'd use:

Me!SubformContr olName.Form!Con trolName

substitute the name of your Subform Control and the name of the Control in
the Form embedded in the Subform Control. I do not name SubformControls with
the "frm" prefix, but instead use "sbf" -- to avoid confusion.

I'm a little puzzled that you'd be using the Reports Collection for Forms.
Yes, it is possible to use a SubForm Control, with an embedded Form, in a
Report. The converse is not true -- you cannot embed a Report in a
Subform/Subreport Control displayed in a Form.

Larry Linson
Microsoft Access MVP
May 10 '06 #2
"Larry Linson" <bo*****@localh ost.not> wrote in
news:HEe8g.2007 8$W83.7509@trnd dc07:

A Form embedded in a Subform Control, even if visible is not "Open"
and, thus, not in the Forms Collection.


I believe it is open but I don't know if it's in the forms collection.

Try this.

1. Put some code in the subform's module or in recent Access versions set
the subform's HasModule property to true.
2. Put a textbox on the subform. Set it's default value to "Larry".
3. Open the main form. Move to the subform. Overwrite Larry with "Lyle"
in the textbox.
4. Leave the main form open.
5. Somewhere, anywhere in the application run this line.
MsgBox Form_subformNam e.textboxName.V alue
ie if the subform's (not the control's) name is OrderItems and the
TextBox's name is Contact then
MsgBox Form_OrderItems .Contact.Value

The subform is definitely open now. If the message box says "Larry" then
clearly it just now opened and returns the default value. If it says
"Lyle" then it was open when you typed in "Lyle (prior to your call to
MsgBox).

Look in your VB editor. Make the Project Explorer visible. You will see
Form_OrderItems in Access Class Objects there. You can refer to
Form_OrderItems anywhere, anytime. It points to the default instance of
the form. If the form isn't open, it opens it (invisible unless its
visiblity is expressly set in its open event code). But if is open it
just points to that instance. And that's what happens here in Canada when
the form is being used as a subform.

As an aside, this gives us a simple way of creating multiple instances of
a form.

Dim SomeOrderItemFo rms(8) as Form_OrderItems gives us an array of 8
unitialized OrderItems forms. We can scan through our array, intialize
each form and give its properties unique values, suvh as Captions, Item
Orders (0), Item Orders (1), Item Orders(2) etc.

--
Lyle Fairfield
May 10 '06 #3
DFS
Lyle Fairfield wrote:
"Larry Linson" <bo*****@localh ost.not> wrote in
news:HEe8g.2007 8$W83.7509@trnd dc07:

A Form embedded in a Subform Control, even if visible is not "Open"
and, thus, not in the Forms Collection.
I believe it is open but I don't know if it's in the forms collection.


It's "open" in the sense that the subform Open and Load events fire when the
main form is opened, but he's right that it's not in the Forms collection.

This old classic is useful for verifying:

Function IsFormLoaded(By Val MyFormName As String) As Integer
Dim i
IsFormLoaded = False
For i = 0 To Forms.Count - 1
If Forms(i).FormNa me = MyFormName Then
IsFormLoaded = True
Exit Function
End If
Next
End Function

Try this.

1. Put some code in the subform's module or in recent Access versions
set the subform's HasModule property to true.
2. Put a textbox on the subform. Set it's default value to "Larry".
3. Open the main form. Move to the subform. Overwrite Larry with
"Lyle" in the textbox.
4. Leave the main form open.
5. Somewhere, anywhere in the application run this line.
MsgBox Form_subformNam e.textboxName.V alue
ie if the subform's (not the control's) name is OrderItems and the
TextBox's name is Contact then
MsgBox Form_OrderItems .Contact.Value

The subform is definitely open now. If the message box says "Larry"
then clearly it just now opened and returns the default value. If it
says "Lyle" then it was open when you typed in "Lyle (prior to your
call to MsgBox).

Look in your VB editor. Make the Project Explorer visible. You will
see Form_OrderItems in Access Class Objects there. You can refer to
Form_OrderItems anywhere, anytime. It points to the default instance
of the form. If the form isn't open, it opens it (invisible unless its
visiblity is expressly set in its open event code). But if is open it
just points to that instance. And that's what happens here in Canada
when the form is being used as a subform.

As an aside, this gives us a simple way of creating multiple
instances of a form.

Dim SomeOrderItemFo rms(8) as Form_OrderItems gives us an array of 8
unitialized OrderItems forms. We can scan through our array, intialize
each form and give its properties unique values, suvh as Captions,
Item Orders (0), Item Orders (1), Item Orders(2) etc.


May 10 '06 #4
Sorry guys I feel such an idiot, this is reports we're working with, I was
looking at the wrong list (forms) and working from memory when I quickly
typed out the message. My message should have been:

I have rptInvoice which has the invoice details (e.g. ProductCode,
ProductCost etc) in the subform rptInvoiceDetai ls. I'm trying to get a field
(AccountID) to show in the parent report based on whether a particular
product code (EXT) is present in the list of ProductCodes on the subreport.
So far I've tried:

IIf(Reports![rptInvoiceDetai ls]![ProductCode]="EXT",Null,[Reports![rptInvoic
e]![AccountID])

Sorry about the confusion!! maybe I should drink more coffee....

Alan
May 10 '06 #5
I have rptInvoice which has the invoice details (e.g. ProductCode,
ProductCost etc) in the subform rptInvoiceDetai ls. I'm trying to get a field (AccountID) to show in the parent report based on whether a particular
product code (EXT) is present in the list of ProductCodes on the subreport. So far I've tried:

IIf(Reports![rptInvoiceDetai ls]![ProductCode]="EXT",Null,[Reports![rptInvoic e]![AccountID])


Actually, I'm guessing this is a timing/loading issue as I can reference
fields on the parent report in the subreport but not vice versa.

Alan
May 10 '06 #6
OK, to make things easier I'm only dealing with the subreport now. The brief
is the same though, I would like to display a label if Product code "EXT" is
present in the product codes listed on the invoice. I can't use syntax like:

IIf([ProductCode]="EXT" etc

Because ProductCode is listed as many times as there are items on the
invoice i.e. it's in the Details section of the report. What's the best way
of going about this?

Alan
May 10 '06 #7

"Alan" <no****@nospam. com> wrote in message
news:U6******** ************@bt .com...
I have rptInvoice which has the invoice details (e.g. ProductCode,
ProductCost etc) in the subform rptInvoiceDetai ls. I'm trying to get a

field
(AccountID) to show in the parent report based on whether a particular
product code (EXT) is present in the list of ProductCodes on the

subreport.
So far I've tried:

IIf(Reports![rptInvoiceDetai ls]![ProductCode]="EXT",Null,[Reports![rptInvoic
e]![AccountID])


Actually, I'm guessing this is a timing/loading issue as I can reference
fields on the parent report in the subreport but not vice versa.


You refer to it the same as a form... just substitute SubreportContro l for
SubformControl in my previous post.

The Reports Collection is, by definition, a Collection of Open Reports. The
Report displayed in a Subreport Control can be used, in many ways, as though
it were Open, but isn't in and therefore can't be referenced using the
Reports collection. It exists as the Report property of the Subreport
Control.

<It's not productive to argue with Lyle over his definition of "Open".>

Assuming the code you describe is in the Format or Print event of the Detail
Section, a reference to a Field will be to that Field in the current record,
not to all occurrences of that Field in the Report. Sometimes, it is worth
trying something that may "seem obvious it will not work" to you.

Larry Linson
Microsoft Access MVP
May 10 '06 #8
> You refer to it the same as a form... just substitute SubreportContro l for
SubformControl in my previous post.

The Reports Collection is, by definition, a Collection of Open Reports. The Report displayed in a Subreport Control can be used, in many ways, as though it were Open, but isn't in and therefore can't be referenced using the
Reports collection. It exists as the Report property of the Subreport
Control.

<It's not productive to argue with Lyle over his definition of "Open".>

Assuming the code you describe is in the Format or Print event of the Detail Section, a reference to a Field will be to that Field in the current record, not to all occurrences of that Field in the Report. Sometimes, it is worth
trying something that may "seem obvious it will not work" to you.

Larry Linson
Microsoft Access MVP

Thanks Larry, I'll give that a go, although I had just resigned myself to
just working within the subreport only to keep things simple! Just having
problems referencing the output of "ProductCod e" as it gets printed many
times within the Details section of the invoice report (according to how
many products have been purchased) so I'm not able to use syntax like:

IIf([ProductCode]="EXT" etc

Alan
May 10 '06 #9
"Alan" <no****@nospam. com> wrote
Just having problems referencing the output of
"ProductCod e" as it gets printed many
times within the Details section of the invoice report
(according to how many products have been
purchased) so I'm not able to use syntax like:

IIf([ProductCode]="EXT" etc


I don't understand where you have put the code that is not working. You
should be working on a separate detail line of the report, if it is in the
Format or Print event... there's just no place in a report where multiple
instances of a single Control are available to VBA. If it _appears_ that is
the problem, you need to dig deeper to discover the real problem.

Do you have both a Control and the underlying Field (ControlSource property
of that Control) with the same identical names? That can cause "confusion, "
despite the beliefs of some here that it is perfectly OK all the time.

Larry Linson
Microsoft Access MVP

May 11 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
2413
by: Michael Charney | last post by:
I have a main report that has a subreport to it. On the sub report I have a running total. If there are no entries in the sub-report source table the sum total returns the #Error message for the running sum total. I want to watch for this on the main report and replace the #Error with a 0 (Zero) in the control on the main report. I can not get this to happen. I have tried both an IF statement in VBA and the IIF in the control itself....
1
474
by: Manal/report designer | last post by:
Thank you in advance for any suggestions... I'm using crystal reports version 8 & SQL server. I've created a report that is composed of 2 parts: 1st part contains the mainreport which uses database1 (db1) located on server1(S1), 2nd part contains the subreport which uses database2 (db2) located on server2 (S2), and I've used (parameter field & a certain fields) to link the subreport to the mainreport. The subreport is composed of 2...
2
2152
by: Nothing | last post by:
I have a main report with several sub-reports on it. Some of the sub-reports are hidden some are visible. A few of the sub-reports hve totals calculated on them. I have a control in the sub-report footer that has a total in it. When I try to reference that control on the main reports header section it seems to be reading just one line of the detail in the sub-report. Not the control with the total. For the life me I can not figure out...
2
2206
by: Keith Wilby | last post by:
A97 I have a report/sub-report setup and for some records in the main report, the sub-report is blank. I want to set the height of the sub-report to zero where it is blank. I've set all the "Can shrink" properties to 'yes' but I'm having trouble with the syntax referencing the text boxes on the sub- report. I get run-time error 2445 (you entered an expression that has an invalid reference to the property form/report) on the first line...
7
1895
by: ChadDiesel | last post by:
Hello everyone, I'm having a problem with Access that I need some help with. The short version is, I want to print a list of parts and part quantities that belong to a certain part group---One list per page. I created a report that groups the parts by part classification group with a force new page after each group. The report is based on a query of that week's orders. Some of these parts have drawings (usually 2 each stored in an...
2
2367
by: Jimmy | last post by:
On the subreport, records are grouped by WorkDate. In the WorkDate header there is a textbox named DateCounter with the control source =1 and running sum set to yes. In either the report footer or the WorkDate footer (I tried both with no difference) is a textbox called DateCount, the control source of which is =DateCounter. If this subreport is run as a seperate report, DateCounter shows 1...2...3...etc for each seperate WorkDate and...
1
1902
by: Susan-MN | last post by:
I’ve just recently started working with Access at my new job. I’ve been able to figure out quite a bit on my own, but I’m stuck with a problem I can’t seem to find answer to on the Access help or website – nor the “Access Bible” I’ve been using as a reference guide. My question is – I’ve created a large report with several subreports on the main report. The information is all linked but my problem comes when I preview the report, if...
4
1664
by: Wook | last post by:
Ok I got a set of Forms Reports etc it goes like this Reports Form Passes a Filter to the report for the needed results The filter it passes along is fine except one problem I need a way for the subreport to also be filtered by the same data The main report name is Dayville Review Report and the subreport is Dayville Review subreport Now all the info from the Form is passed into the vba environment for double checking when I was just...
12
8029
D Giles
by: D Giles | last post by:
Access 2003: A subreport control (sum total calculated textbox located in the subreport report footer) does not show total of all records when referenced as a total in the main report footer - only shows one record amount. When I open the subreport alone, it totals the sum of all the records which the query pulls - which is what I want. The referenced textbox in the main report footer only shows one record amount. Why is the total in the main...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8097
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
6702
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
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4519
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
4784
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
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
2635
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.