473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Multiple Subreports and field references in Subforms

convexcube
Hi everyone,

This is just a little rundown of a problem I discovered & the solution I found:

I have a report which runs off a query (query1). Within the report there are also 2 subreports which run off a further 2 queries. These 2 queries are both related to query1, and query1 uses a reference to a subform control in a criteria field. So in essence, to get any results in the report the value of the control in the subform is paramount and must be available before any of the calculations begin.

The problem I found is that this was not the case. The calculations of the queries would start before the value was retrieved from the control and the queries would then ask for parameter input, and also calculated controls on the main report didn't show a result but "Name?" instead. Although, the controls that directly referenced fields in query1 worked perfectly, so I knew the query was able to get the value from the subform control - it just seemed not quickly enough.

After much trial and tribulation with the syntax of the reference, I decided to make a hidden textbox on the main form that referenced the control on the subform. I then made query1 reference this textbox to get the value and now the whole report runs as it should.

I hope this tip can help someone and I invite further discussion on why this step was necessary to make it work.

Regards,
Ken.
Dec 15 '07 #1
10 1989
NeoPa
32,556 Expert Mod 16PB
It's a nice idea to post this ken, but I'm not sure we have enough detail to determine why this is behaving this way.
I wouldn't anticipate a subform control (correctly accessed) to behave any differently in your scenario from a control on the main form. Maybe it's your referencing the item that's wrong. It's hard to know for sure without access to all the details.
Dec 17 '07 #2
Hi NeoPa,

Before coming up with this solution, I tried all the variants of referencing from an external module as you describe in this article (an excellent article, btw). Specifically:
  1. Forms![FormName]![SubFormName].Form![ControlName]
  2. Forms("FormName")![SubFormName].Form![ControlName]
  3. Form_FormName![SubFormName].Form![ControlName]
One thing I didn't mention before is that I was able to get these to work initially, but when i saved and reloaded the database, it would display the behaviour I described in my previous post.
So I don't think the referencing syntax that was the problem. Other than this, while not specific I believe I supplied fairly detailed information. What extra information should I provide?
At any rate, I am pleased that I have found a solution that works, however inelegant it may be.

Regards,
Ken.
Dec 18 '07 #3
NeoPa
32,556 Expert Mod 16PB
...
(an excellent article, btw)
...
Thanks :)
...
So I don't think the referencing syntax that was the problem. Other than this, while not specific I believe I supplied fairly detailed information. What extra information should I provide?
You did. I understood the situation you were describing. I simply didn't have enough detailed information upon which to build an idea of what was wrong. Remote diagnosis is actually heavily dependant on detailed information (most of the time - some questions are obvious). In your situation it was certainly not obvious what was wrong. You seemed to have a reasonable understanding of the issues, so what do I look for to explain it not working? The details is my only option.
The "#Name?" error generally means that something that you're trying to reference is not correctly done. I'm not aware this can be a timing issue. To progress my theory I'd need the details of the SQL and the reference in particular. Basically everything I need to check to try to determine what's going on for you.
At any rate, I am pleased that I have found a solution that works, however inelegant it may be.
And so am I. I wasn't trying to criticise your solution.
Dec 18 '07 #4
Hi NeoPa,

First of all, I would like to thank you for taking the time to look at my issue, especially since I have a solution in place. After reading a lot of other posts I can understand why it can be frustrating when not enough information is supplied.

Here is the SQL of the query the main report is based on (note the reference to the subform in the WHERE statement):

Expand|Select|Wrap|Line Numbers
  1. SELECT Employees.*
  2. FROM Employees
  3. WHERE Employees.EmployeeIndex=Forms![Main]![Employees].Form![txtEmployeeIndex];
Then the SQL for the first subreport is as follows (it selects all events that are not uniform events for a specific employee - which is related to the sql of the main report (EmployeeDetailQuery):

Expand|Select|Wrap|Line Numbers
  1. SELECT Events.EventIndex, Events.EmployeeNumber, Events.EventDate, Events.EventType, Events.EventDetail, Events.RecordedBy, Events.ActionedBy, Events.ActionedOn, Events.LastEditedBy, Events.LastEditedOn
  2. FROM Events INNER JOIN EmployeeDetailQuery ON Events.EmployeeNumber = EmployeeDetailQuery.EmployeeIndex
  3. WHERE Events.EventType<>"4"
  4. ORDER BY Events.EventDate DESC;
The second subreport has to work on events that are only uniform events so I must use an alternate query (EmployeeUniformEventsQuery) as an additional source which selects only the uniform events for this specific employee:

Expand|Select|Wrap|Line Numbers
  1. SELECT Events.EventIndex, Events.EmployeeNumber, Events.EventDate, Events.EventType, Events.EventDetail, Events.RecordedBy, Events.ActionedBy, Events.ActionedOn, Events.LastEditedBy, Events.LastEditedOn
  2. FROM Events INNER JOIN EmployeeDetailQuery ON Events.EmployeeNumber = EmployeeDetailQuery.EmployeeIndex
  3. WHERE Events.EventType="4"
  4. ORDER BY Events.EventDate DESC;
then the SQL for the second subreport is

Expand|Select|Wrap|Line Numbers
  1. SELECT Uniforms.EventDate, Uniforms.UniformItem, Uniforms.ItemPrice, Uniforms.RecordedBy, EmployeeUniformEventsQuery.LastEditedBy, EmployeeUniformEventsQuery.LastEditedOn, Uniforms.EventIndex
  2. FROM EmployeeUniformEventsQuery INNER JOIN Uniforms ON EmployeeUniformEventsQuery.EventIndex = Uniforms.EventIndex
  3. ORDER BY Uniforms.EventDate DESC;
I apologise for the lack of naming conventions in these statements. This database was started before I had read up on that. The reference to the subform was tried in all syntaxes that you outlined in your article.

A couple of points I am pondering on are:
  1. Could using SELECT * in the main report query rather than specifically referencing each field be a factor?
  2. I noticed when I entered the subform reference in the main report query that it would apply square brackets around each of the sections like this: [Forms]![Main]![Employees].[Form]![txtEmployeeIndex]. This seemed to invalidate the reference, so in SQL view I removed them to read as the syntax of your article. Then, when I ran the report it would work. After saving and reloading the database, the adjusted reference would remain intact in SQL view, but running the report would ask for parameter input, and calculated controls showed the "#Name?" Error, even after entering the Employee Index manually. Though directly referenced fields would show correctly.

Whew! That was a long one. Hopefully I have provided enough information for you. There's no need for a quick response though. Once again, thanks for helping me nut this out.

Regards,
Ken.
Dec 19 '07 #5
NeoPa
32,556 Expert Mod 16PB
A long post indeed :)
I will try to go through it properly this evening and see if I can see anything that might explain what you're seeing. It's entirely possible that I won't, but I'll post what I can anyway, giving particular attention to the last two points (questions) you raise.
Until later then.
Dec 20 '07 #6
NeoPa
32,556 Expert Mod 16PB
I'm afraid at past midnight I haven't found time to look at this tonight.
I will try tomorrow (late again I'm afraid as it's setting up to become a busy day).
Dec 21 '07 #7
No worries Neo. Take your time.

Regards,
Ken.
Dec 21 '07 #8
NeoPa
32,556 Expert Mod 16PB
...
A couple of points I am pondering on are:
  1. Could using SELECT * in the main report query rather than specifically referencing each field be a factor?
  2. I noticed when I entered the subform reference in the main report query that it would apply square brackets around each of the sections like this: [Forms]![Main]![Employees].[Form]![txtEmployeeIndex]. This seemed to invalidate the reference, so in SQL view I removed them to read as the syntax of your article. Then, when I ran the report it would work. After saving and reloading the database, the adjusted reference would remain intact in SQL view, but running the report would ask for parameter input, and calculated controls showed the "#Name?" Error, even after entering the Employee Index manually. Though directly referenced fields would show correctly.
...
Ken,
As these two points seem to be the crux of the matter I'll deal first with them.
  1. I'm really not sure about this. I believe it does make a difference, but probably only in performance and optimisation. I don't think this would effect any referencing you make anywhere.
  2. Access has a nasty habit of doctoring SQL in such a way as to stop it from working. Play with parenthesised subqueries for an illustration of this. Strangely enough, the "fixed / mucked" SQL Access produces doesn't typically cause a problem until you try to make a change somewhere in the SQL itself. Then it complains about the SQL it's created :(
    It sound like this may well be what your problem is related to though. Hard to be definite, but it rings true to me.
Other ideas :
  1. Clearly your current idea of adding a hidden control on the main form works.
  2. It should be possible to update the RecordSource of your reports on-the-fly in the OnOpen event procedure. Inserting the value got from the form (subform) into the SQL itself as a literal value should produce the results you want quite reliably. You can even check the contents first and abort if there is no data in the control.
Dec 21 '07 #9
Thanks Neo,

The points you raise make sense to me. For the moment I'm going to leave it as is, but I may have to look into building the SQL on the fly because I have several more reports structured like this to build yet and I would like to abort the print out if there are no records to show.

Once again, thanks for taking the time to look into it for me and I hope you and your family have a great Christmas & holiday season.

Kind Regards,
Ken.
Dec 21 '07 #10
NeoPa
32,556 Expert Mod 16PB
No problems Ken and thank you for the Christmas wishes. You can have them right back of course, you and your whole family. Have a very Merry Christmas and a Happy New Year.

As you're interested in terminating a report that has no data in it, I'll just mention that there is an "On No Data" event. Coding this up is very simple and consists of the following (or more if required) :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Report_NoData(Cancel As Integer)
  2.     Cancel = True
  3. End Sub
Dec 22 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a form with multiple pages on it. There is one text field on the third page of the form that I need the user to complete before leaving the form or moving...
1
by: Steve | last post by:
I am using Access 2000 and I have a DB that is currently running four different queries from some Forms and subforms. These queries each have a date field that are seperate from each other that are...
3
by: Diana Gard | last post by:
Perhaps this is a design flaw, please let me know. I'm using Access 2000. I have a form with a tab control and 5 subforms within those tabs. The forms match with the tables: Client main,...
0
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
4
by: microb0x | last post by:
I have an application with a master form with a tab control containing nine tabs, each tab contains a subform. I have command buttons on my main form including: Save , Cancel , Close. My...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform relates to the main form using an identity key (this works). The second subform relates to both the main and first subform. But I want to...
1
by: natwong | last post by:
Hi All, I'm hoping that someone could help me out since I'm new with Access. Background: Database was set up as a simple data entry and reporting tool for Program Initiatives. The data...
6
by: Brett Barry: Go Get Geek! | last post by:
Hello, I have a main report with a Record Source, a DateToday table, that has the current Month and Year. I have about 60 queries, each pulling different data via ODBC, that I am creating...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.