473,395 Members | 1,442 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,395 software developers and data experts.

Choosing between subreports in a report

204 128KB
I have a report where in two places (43a and 43b) I need to insert one of three subreports, depending on who is paying. I used the following code in the Current event:
Private Sub Report_Current()

If Queries.qry_LOI.[Who_pays] = "B" Then
Set Me.[subrpt_43a_BothPay].Visible = True:
Set Me.[subrpt_43a_PilgrimPays].Visible = False:
Set Me.[subrpt_43a_SponsorPays].Visible = False:
Set Me.[subrpt_43b_BothPay].Visible = True:
Set Me.[subrpt_43b_PilgrimPays].Visible = False:
Set Me.[subrpt_43b_SponsorPays].Visible = False
ElseIf Queries.qry_LOI.[Who_pays] = "S" Then
Set Me.[subrpt_43a_BothPay].Visible = False:
Set Me.[subrpt_43a_PilgrimPays].Visible = False:
Set Me.[subrpt_43a_SponsorPays].Visible = True:
Set Me.[subrpt_43b_BothPay].Visible = False:
Set Me.[subrpt_43b_PilgrimPays].Visible = False:
Set Me.[subrpt_43b_SponsorPays].Visible = True
Else
Set Me.[subrpt_43a_BothPay].Visible = False:
Set Me.[subrpt_43a_PilgrimPays].Visible = True:
Set Me.[subrpt_43a_SponsorPays].Visible = False:
Set Me.[subrpt_43b_BothPay].Visible = False:
Set Me.[subrpt_43b_PilgrimPays].Visible = True:
Set Me.[subrpt_43b_SponsorPays].Visible = False
End If

End Sub

However it doesn't work. If I scroll down in report view the subreports all stay visible, but if I page down I get a VBA compile error on the word "Visible", saying "Invalid use of property".

Can anyone see what I'm doing wrong?
Oct 13 '16 #1

✓ answered by PhilOfWalton

Nearly got me beaten... but not quite.

Reports that are not in Print Preview do funny things, so only check in Print preview.

I have just noticed I left a "Set" in the code I posted to you. That definitely should not be there.

Try cutting the code down even further to
Expand|Select|Wrap|Line Numbers
  1.     Me.[subrpt_43a_BothPay].Visible = True
  2.  
and Ditto for false, so the value of Who_pays is irrelevant. This will confirm the statement is working correctly

Try putting the code on the OnFormat of the Detail, not the OnCurrent of the Peport.

Phil

17 1073
Seth Schrock
2,965 Expert 2GB
I find that events in reports don't work the way that they do in forms. I'm guessing that if you put a break point somewhere in your code, you will find that it doesn't run when you open it in Report View. Try opening it in Print Preview and see if it works. Also, try moving your code to the On_Load event.
Oct 18 '16 #2
Petrol
204 128KB
Thank you, Seth, but the problem I am having is that when it gets to the specified event (irrespective of whether it's Current or Load) it gets a compile error "Invalid use of property" with the first occurrence of the word "Visible" highlighted. Does anyone know what that message means?

I tried replacing the Set statements with Let statements, but that just gives error 424, "Object required". The same thing happens if I leave them as Set statements but replace the Me. with Me!. Unfortunately I can't find out what they mean by "object required", either.
Oct 19 '16 #3
PhilOfWalton
1,430 Expert 1GB
This is purely a guess, but a subreport is just a control on the main report (as is a text box or label).

So you don't need any "Sets" or "Lets"

This sort of thing should be fine:

Expand|Select|Wrap|Line Numbers
  1. Me.[subrpt_43b_SponsorPays].Visible = False
  2.  

Phil
Oct 19 '16 #4
Petrol
204 128KB
Without the Set it still gave the error 424, "Object required", whatever that means.
Oct 19 '16 #5
PhilOfWalton
1,430 Expert 1GB
Something similar works OK on my database, so

Firstly, remove the colon at the end of your statements.

Secondly, Do you have a subreport for example whose NAME is "subrpt_43a_BothPay"?

Thirdly, as a test, simplyfy the statement. Try something like

Expand|Select|Wrap|Line Numbers
  1. If Queries.qry_LOI.[Who_pays] = "B" Then
  2.     Me.[subrpt_43a_BothPay].Visible = True
  3. Else
  4.     Set Me.[subrpt_43a_BothPay].Visible = False
  5. End If
  6.  
Fourthly, Is "Queries.qry_LOI.[Who_pays]" giving a value. That looks very very odd to me.

Phil
Oct 19 '16 #6
Petrol
204 128KB
Thanks Phil. I had looked at that code scores of times and never noticed the colons at the end. I have no idea why I put them there! I have now taken them out.
However, removing them didn't solve the problem :(

Secondly, yes all the named subreports are present.

Thirdly, I have now cut the subroutine down to the simplified version you suggested. If I include the "Set" keyword in the result clauses I get "Compile error: invalid use of property" with the first line of the If statement highlighted.
If I leave the Set keyword out, I get "Runtime error 424, object required" with the property "Visible" highlighted.

These things happen
(a) in Report view, when I page down the report; and
(b) in Layout view, immediately the report is opened.
In Print Preview, I don't get either error - but the subreports don't become visible either :(

As to your fourth suggestion, yes, there is a single-character field named Who_pays in the query on which the report is based. I can add a control to the report to display it and it shows OK.

This whole thing is driving me crazy. I've been chasing it on and off for weeks now !
Oct 19 '16 #7
PhilOfWalton
1,430 Expert 1GB
Nearly got me beaten... but not quite.

Reports that are not in Print Preview do funny things, so only check in Print preview.

I have just noticed I left a "Set" in the code I posted to you. That definitely should not be there.

Try cutting the code down even further to
Expand|Select|Wrap|Line Numbers
  1.     Me.[subrpt_43a_BothPay].Visible = True
  2.  
and Ditto for false, so the value of Who_pays is irrelevant. This will confirm the statement is working correctly

Try putting the code on the OnFormat of the Detail, not the OnCurrent of the Peport.

Phil
Oct 19 '16 #8
Petrol
204 128KB
OK, thanks, Phil. At last I have had time to do some more extensive testing. It seems that the reason I have been having so much trouble is that there were not one but 3 problems with my code:
(1) I had un-noticed colons at the end of my statements, for some reason; thanks for spotting them, Phil.
(2) I was using Set in my assignment statements (because of a misreading of the material at https://msdn.microsoft.com/en-au/library/6b85bc00.aspx), which seems to suggest Set is required for setting properties;
(3) The If test doesn't work.

Fairly extensive testing reveals that most of the events do get called in Report or Layout view as well as in Print Preview, as per the documentation. Specifically, Open-Load-Activate-GotFocus-Current, except that GotFocus doesn't occur in Layout view and in Print Preview it is followed by a series of Detail events (Format-Print-Page) for each page.

The one remaining issue - and it is a critical one - is that the If test doesn't work. It gives rise to Error 424, "Object required". The If statements are of the form
If Queries.qry_LOI.[Who_pays] = "x" Then ....
qry_loi is the underlying query on which the form is based, and [Who_pays} is a single-character field in that query which I can display through a control on the form, so I don't know why I can't test it. It is critical for me to be able to modify the reports, which are produced for a series of clients, depending on the value of this parameter.

Can anyone suggest how I can go forward?
Oct 22 '16 #9
Petrol
204 128KB
Ok, solved.
(1) it doesn't like the fully-qualified "Queries.qry_LOI.[Who_pays]", but when I substitute simply "who_pays" it works OK. Don't know why.
(2) And as Phil suggested, the code needs to be in Detail's OnFormat, as Open, Load, Activate and GotFocus fire only once when the report starts, not once for each record.
Finally the thing works!
Oct 22 '16 #10
PhilOfWalton
1,430 Expert 1GB
Glad you,ve got it working.

With a report, the OnOpen is often used to change the recordsource or filter. Most of the formatting takes place on the OnFormat of the various sections.

Again, I stress that reports should always be viewed in print preview. It's so tempting to double click the report name in the Nav Pane, but resit this urge.

I did mention I didn't like the look of "Queries.qry_LOI.[Who_pays]". My approach would be to put the WhoPays control in the detail section of the report and, optionally set it's visibility to false.

Phil
Oct 22 '16 #11
Petrol
204 128KB
Good idea. Without that the event procedure can't find it.

One further question. The subreports are different sizes - 2, 4 and 6 lines. I have set the report detail section CanGrow and CanShrink to yes, but it doesn't. If the text below the subreport is placed just under the text above the subreport it is overlaid, while if I leave 6 lines of space between them there is a big gap with the 2-line subreports.
Any idea what I have to do to make CanShrink work?
Oct 22 '16 #12
PhilOfWalton
1,430 Expert 1GB
I presume that the subreports and any associated labels are also set to CanShrink & CanGrow. Also make sure that you have a sensible size grid that you can see and align everything to the grid to ensure there are no overlapping controls.

Difficult to know without seeing the report.

Phil
Oct 22 '16 #13
Petrol
204 128KB
Yes ... the report detail section is set to CanGrow and CanShrink, and so are the three subreports. There are text blocks ("Labels" in Access terminology) immediately above and immediately below the space for the subreports, and just enough space left in between them for the largest (6 lines) subreport. All sub-reports are overlaid on one another in the space in between, but there is no overlap with the labels above or below, and only one of them can be visible at any one time. When a smaller (2 or 4 line) subreport is is made visible (and the others invisible) there is white space between it and the following text block.

If I move the following text block up to eliminate the space, then the larger sub-reports overlay the text block.
Oct 22 '16 #14
PhilOfWalton
1,430 Expert 1GB
Looking at your code again. you define 6 subreports. Vis

Expand|Select|Wrap|Line Numbers
  1. subrpt_43a_BothPay
  2. subrpt_43b_BothPay
  3. subrpt_43a_PilgrimPays
  4. subrpt_43b_PilgrimPays
  5. subrpt_43b_SponsorPays
  6. subrpt_43a_SponsorPays
  7.  
Yet you say there are only 3. Don't know if this makes a difference.

Phil
Oct 22 '16 #15
Petrol
204 128KB
No, the 43a ones occupy the same space on page 1; the 43b ones occupy the same space on page 2, but since these ones are the same size it's not an issue. Page 1 is a letter and should look good. Page 2 is just a form to be enclosed with the letter, and spacing is not an issue there.
Oct 22 '16 #16
PhilOfWalton
1,430 Expert 1GB
Without actually seeing the DB, I am reluctant to make further comments.

It might be worth experimenting with only putting 3 subrports on your main report, reducing the report to a single page and altering the code accordingly to see if that will work.

Alternatively, you, might experiment with the subreport's .top and .Height
Oct 23 '16 #17
Petrol
204 128KB
Thanks for all your help, Phil.
I'm experimenting with the Top property of the following label - looks as though it might be the answer since Shrink doesn't seem to work.
Thanks again. You've been very persistent and very helpful!
Peter
Oct 23 '16 #18

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

Similar topics

4
by: deko | last post by:
I can't move a multi-page report to the last record unless I keep the popup form (that defined it's subreports) open. DoCmd.OpenReport "rptStandard", acViewNormal DoCmd.Close acForm,...
6
by: David B | last post by:
I have a report with 2 sub reports on it. The report is an invoice and the sub reports are dropping data onto the invoice. This worked fine if generating 1 invoice at a time. I am trying to create...
3
by: Edward | last post by:
ACCESS 2k I need to design a report based on a rota system for staff at various shops. The data is effectively stored in a single table, along the lines of: Initials (e.g. BH, FG, RM etc.)...
1
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
0
by: Don Sealer | last post by:
I have a report that includes 5 different subreports. I'd like to be able to open this report using a date function (Start Date and End Date). I'd like all five subreports to show the data from...
1
by: El | last post by:
I have a table called Product Code Master with fields Product_Code and Description. Currently, I have individual reports set up for different types of products and the user simply clicks a macro...
1
by: David | last post by:
Folks, I have four subreports in a report in the detail section. I suppose I could move them to the footer of the report. Anyway, if any of them have data, I want the main report to force a...
3
by: Jimmy | last post by:
Is there a way to force access to wait a specified time before making a calculation? On my report there is a subreport with a number of calculation on it. One if which is a count of certain...
2
by: kabradley | last post by:
Hello everyone. I have three reports that I would like to put into one main report. I tried creating the main report and then putting three seperate subreports in the detail section of the parent...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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.