Question

Using Recordsets to resolve "Procedure too large" Error.

Asked by: billcute

I have a module pulling 12 strings for a report and I usually receive procedure too large error, how can I use recordset to resolve this problem?

Public Function MyRptYear() As String
Dim SQLstr As String
SQLstr = "SELECT tblTPlant.TPlant AS TPlantID, "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "
        SQLstr = SQLstr & "  
MyRptYear = SQLstr
Exit Function
End Function

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-09-10 at 04:11:00ID21983992
Tags

functions

,

i

,

too

,

use

Topic

Microsoft Access Database

Participating Experts
3
Points
500
Comments
26

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Dim Database, Recordset
    In a form.....how often must I Dim a database...and a recordset.... In other words, if the various code I write (mostly in command buttons) is different....do I have to continually Dim....? or.can I dim once in the general declarations section....???
  2. passing recordset to a procedure
    Is there a way to pass a recordset down to a procedure? thanks, jptu
  3. Close the recordset or not ?
    We are currently having a debate of wether it is necessary to close opened recordsets or not if the recordset variable is being set to nothing at the end of the code. Microsofts examples does very seldom include the set rs = nothing part even though this is necessary to compl...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: MikeToolePosted on 2006-09-10 at 04:41:24ID: 17489147

Hi,
It would be a good starting point if you posted the code that causes the Procedure too large error. There also apears to be a lot missing from the function you posted - it wouldn't compile as it is, and there doesn't seem a point in returning a SQL string as the result of the MyRptYear() function.

 

by: billcutePosted on 2006-09-10 at 05:26:01ID: 17489241

Here is the complete string SQL

Public Function MyRptYear() As String
Dim SQLstr As String
SQLstr = "SELECT tblTPlant.TPlant AS TPlantID, "
        SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=1 And IsNull([SID])=False " & _
        "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ1, Sum(IIf([SConnTypeID]='NC' " & _
        "And DatePart('q',[permitedate])=1,[SanFlow],0))AS [San FlowQ1], Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=1 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ1, " & _
        "Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=1,[PlugFlow],0)) AS [Plug FlowQ1], " & _
        "([San FlowQ1]*0.65)-([Plug FlowQ1]*0.65) AS [Net FlowQ1], "
    SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=2 And IsNull([SID])=False " & _
        "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ2, Sum(IIf([SConnTypeID]='NC' " & _
        "And DatePart('q',[permitedate])=2,[SanFlow],0))AS [San FlowQ2], Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=2 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ2, " & _
        "Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=2,[PlugFlow],0)) AS [Plug FlowQ2], " & _
        "([San FlowQ2]*0.65)-([Plug FlowQ2]*0.65) AS [Net FlowQ2],"
    SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3 And IsNull([SID])=False " & _
        "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ3, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3, " & _
        "[SanFlow],0))AS [San FlowQ3], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3 And IsNull([SID])=False " & _
        "And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ3, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3,[PlugFlow],0)) " & _
        "AS [Plug FlowQ3], ([San FlowQ3]*0.65)-([Plug FlowQ3]*0.65) AS [Net FlowQ3],"
    SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) " & _
        "AS NCCountQ4, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4,[SanFlow],0))AS [San FlowQ4], Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ4, Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=4,[PlugFlow],0)) AS [Plug FlowQ4], ([San FlowQ4]*0.65)-([Plug FlowQ4]*0.65) AS [Net FlowQ4] "
    SQLstr = SQLstr & "FROM tblTPlant INNER JOIN tblSewer ON tblTPlant.TPlantID = tblSewer.TPlantID "
    SQLstr = SQLstr & "WHERE (((tblSewer.SewerTypeID) = 'SA' Or (tblSewer.SewerTypeID) = 'CM') " & _
        "And ((DatePart('yyyy', [PermitEDate])) = " & [Forms]![Report Date Range]![input year] & ") And ((tblSewer.TPlantID) Is Not Null) " & _
        "And ((tblSewer.PermitEDate) Is Not Null) And ((tblSewer.CIDate) Is Not Null) And ((tblSewer.PermitNo) Is Not Null)) "
    SQLstr = SQLstr & "GROUP BY tblTPlant.TPlant; "
   
MyRptYear = SQLstr
Exit Function
End Function
' *********

Private Sub Report_Open(Cancel As Integer)
   Me.RecordSource = MyRptYear()
End Sub

 

by: MikeToolePosted on 2006-09-10 at 07:30:13ID: 17489629

Which line of code is highlighted when you get the error? The size limit for a procedure is 64K which you don't reach here.

 

by: mcallarsePosted on 2006-09-10 at 07:36:22ID: 17489643

There is a line continuation limit in VB. What version of Access are you running?

 

by: mcallarsePosted on 2006-09-10 at 07:37:47ID: 17489647

Nevermind, I see the lines are broken up.

 

by: billcutePosted on 2006-09-10 at 12:21:59ID: 17490400

MikeToole,
I have no problem with my home Access 2003. My office is still glued to Access 2K. When I run the same code in the office I get the "Procedure too large error"

on...

Me.RecordSource = MyRptYear()


I am hoping to try a work around ...may be using a recordset might reslove the problem. ..

I noticed that "rockiroads" used same technique very recently at the link below:
http://www.experts-exchange.com/Databases/MS_Access/Q_21983364.html

Regards
Bill

 

by: mbizupPosted on 2006-09-10 at 12:33:48ID: 17490423

Bill,

Does breaking up the function help?  


Public Function MyRptYear1() As String
Dim SQLstr As String
SQLstr = "SELECT tblTPlant.TPlant AS TPlantID, "
        SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=1 And IsNull([SID])=False " & _
        "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ1, Sum(IIf([SConnTypeID]='NC' " & _
        "And DatePart('q',[permitedate])=1,[SanFlow],0))AS [San FlowQ1], Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=1 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ1, " & _
        "Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=1,[PlugFlow],0)) AS [Plug FlowQ1], " & _
        "([San FlowQ1]*0.65)-([Plug FlowQ1]*0.65) AS [Net FlowQ1], "
   MyRptYear1 = SQLstr
End Function


Public Function MyRptYear2() As String
Dim SQLstr As String
   SQLstr = "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=2 And IsNull([SID])=False " & _
        "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ2, Sum(IIf([SConnTypeID]='NC' " & _
        "And DatePart('q',[permitedate])=2,[SanFlow],0))AS [San FlowQ2], Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=2 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ2, " & _
        "Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=2,[PlugFlow],0)) AS [Plug FlowQ2], " & _
        "([San FlowQ2]*0.65)-([Plug FlowQ2]*0.65) AS [Net FlowQ2],"
   MyRptYear2 = SQLstr
End Function


Public Function MyRptYear3() As String
Dim SQLstr As String
    SQLstr = "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3 And IsNull([SID])=False " & _
        "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ3, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3, " & _
        "[SanFlow],0))AS [San FlowQ3], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3 And IsNull([SID])=False " & _
        "And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ3, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3,[PlugFlow],0)) " & _
        "AS [Plug FlowQ3], ([San FlowQ3]*0.65)-([Plug FlowQ3]*0.65) AS [Net FlowQ3],"
   MyRptYear3 = SQLstr
End Function


Public Function MyRptYear4() As String
Dim SQLstr As String
    SQLstr = "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) " & _
        "AS NCCountQ4, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4,[SanFlow],0))AS [San FlowQ4], Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ4, Sum(IIf([SConnTypeID]='PL' " & _
        "And DatePart('q',[permitedate])=4,[PlugFlow],0)) AS [Plug FlowQ4], ([San FlowQ4]*0.65)-([Plug FlowQ4]*0.65) AS [Net FlowQ4] "
   MyRptYear4 = SQLstr
End Function

Public Function MyRptYear5() As String
Dim SQLstr As String
    SQLstr = SQLstr & "FROM tblTPlant INNER JOIN tblSewer ON tblTPlant.TPlantID = tblSewer.TPlantID "
    SQLstr = SQLstr & "WHERE (((tblSewer.SewerTypeID) = 'SA' Or (tblSewer.SewerTypeID) = 'CM') " & _
        "And ((DatePart('yyyy', [PermitEDate])) = " & [Forms]![Report Date Range]![input year] & ") And ((tblSewer.TPlantID) Is Not Null) " & _
        "And ((tblSewer.PermitEDate) Is Not Null) And ((tblSewer.CIDate) Is Not Null) And ((tblSewer.PermitNo) Is Not Null)) "
    SQLstr = SQLstr & "GROUP BY tblTPlant.TPlant; "
   MyRptYear5 = SQLstr
End Function
' *********

Private Sub Report_Open(Cancel As Integer)
   Me.RecordSource = MyRptYear1  &  MyRptYear2  &  MyRptYear3 &  MyRptYear4  &  MyRptYear5
End Sub

 

by: MikeToolePosted on 2006-09-11 at 02:31:43ID: 17492790

Bill,
Unfortunately, for some strange reason, the Recordset property can only be used for reports in an access project - it's not supported in an mdb.
I'm still a little puzzled that you hit the 64K limit. Is there any other code in Report_Open() ?
One thing you can try is to move the assignment of the recordsource from Report_Open() to the MyRptYear function.
Mike

 

by: billcutePosted on 2006-09-11 at 02:52:30ID: 17492928

MikeToole,
The report has a sub report as welll...but please post the entire string SQL with your suggested assignment of the recordsource to "MyRptYear" Function.

Regards
Bill

 

by: billcutePosted on 2006-09-11 at 02:53:43ID: 17492935

mbizub,
I will test your suggestion in the office today and let you know later.

Regards
Bill

 

by: MikeToolePosted on 2006-09-11 at 03:30:05ID: 17493223


Public Sub AssignRecordSource(rpt As Report)
Dim SQLstr As String
  SQLstr = "SELECT tblTPlant.TPlant AS TPlantID, "
  SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=1 And IsNull([SID])=False " & _
      "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ1, Sum(IIf([SConnTypeID]='NC' " & _
      "And DatePart('q',[permitedate])=1,[SanFlow],0))AS [San FlowQ1], Sum(IIf([SConnTypeID]='PL' " & _
      "And DatePart('q',[permitedate])=1 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ1, " & _
      "Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=1,[PlugFlow],0)) AS [Plug FlowQ1], " & _
      "([San FlowQ1]*0.65)-([Plug FlowQ1]*0.65) AS [Net FlowQ1], "
  SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=2 And IsNull([SID])=False " & _
      "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ2, Sum(IIf([SConnTypeID]='NC' " & _
      "And DatePart('q',[permitedate])=2,[SanFlow],0))AS [San FlowQ2], Sum(IIf([SConnTypeID]='PL' " & _
      "And DatePart('q',[permitedate])=2 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ2, " & _
      "Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=2,[PlugFlow],0)) AS [Plug FlowQ2], " & _
      "([San FlowQ2]*0.65)-([Plug FlowQ2]*0.65) AS [Net FlowQ2],"
  SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3 And IsNull([SID])=False " & _
      "And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ3, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3, " & _
      "[SanFlow],0))AS [San FlowQ3], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3 And IsNull([SID])=False " & _
      "And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ3, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3,[PlugFlow],0)) " & _
      "AS [Plug FlowQ3], ([San FlowQ3]*0.65)-([Plug FlowQ3]*0.65) AS [Net FlowQ3],"
  SQLstr = SQLstr & "Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) " & _
      "AS NCCountQ4, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4,[SanFlow],0))AS [San FlowQ4], Sum(IIf([SConnTypeID]='PL' " & _
      "And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ4, Sum(IIf([SConnTypeID]='PL' " & _
      "And DatePart('q',[permitedate])=4,[PlugFlow],0)) AS [Plug FlowQ4], ([San FlowQ4]*0.65)-([Plug FlowQ4]*0.65) AS [Net FlowQ4] "
  SQLstr = SQLstr & "FROM tblTPlant INNER JOIN tblSewer ON tblTPlant.TPlantID = tblSewer.TPlantID "
  SQLstr = SQLstr & "WHERE (((tblSewer.SewerTypeID) = 'SA' Or (tblSewer.SewerTypeID) = 'CM') " & _
      "And ((DatePart('yyyy', [PermitEDate])) = " & [Forms]![Report Date Range]![input year] & ") And ((tblSewer.TPlantID) Is Not Null) " & _
      "And ((tblSewer.PermitEDate) Is Not Null) And ((tblSewer.CIDate) Is Not Null) And ((tblSewer.PermitNo) Is Not Null)) "
  SQLstr = SQLstr & "GROUP BY tblTPlant.TPlant; "
   
    rpt.RecordSource = SQLstr
End Sub

Private Sub Report_Open(Cancel As Integer)
   AssignRecordSource Me
End Sub

 

by: billcutePosted on 2006-09-11 at 03:38:38ID: 17493271

Mike,

Should I place this in a standard module or in the report?

Regards
Bill

 

by: billcutePosted on 2006-09-11 at 03:45:30ID: 17493301

Also, what if the report has a sub report with string as well...so opening "two" AssignmentRecordSource at the same time might not work..?

For example in the current design of my subreport..I have the following code :

Private Sub Report_Open(Cancel As Integer)

Static Started As Boolean                            '<<----- Note this lines
If Not Started Then                                    '<<----- Note this lines
        Me.RecordSource = MyRptSubYear()    '<<----- Note this lines
        Started = True                                  '<<----- Note this lines
        Debug.Print MyRptSubYear()
End If
End Sub
' *********


Bill

 

by: MikeToolePosted on 2006-09-11 at 03:56:04ID: 17493347

Bill,
My assumption was that MyRptYear() was in a standard module, that's why the report object is passed as a parameter in the sub AssignRecordSource(). If you put AssignRecordSource in the Report module, you don't need to pass the parameter

You can do the same thing for the sub-report if you convert MyRptSubYear to the sub AssignSubRecordSource in the same way as was done for the main report:

Private Sub Report_Open(Cancel As Integer)

Static Started As Boolean                            '<<----- Note this lines
If Not Started Then                                    '<<----- Note this lines
        AssignSubRecordSource me               '<<----- Note this lines
        Started = True                                  '<<----- Note this lines
        Debug.Print MyRptSubYear()
End If
End Sub
'

 

by: billcutePosted on 2006-09-12 at 03:28:09ID: 17501225

mbizub,
I tested your suggestion on Access 2003. It worked. I will definitely test it on Access2K today and let you know later.

Regards
Bill

 

by: billcutePosted on 2006-09-12 at 03:36:12ID: 17501262

Mike,
I first converted the sub report to :"AssignSubRecordSource" then posted each code below in the Sub Report open at different times, then tried running the report in Access 2003. There were no errors.."only" the main report showed the sub did not show.

Private Sub Report_Open(Cancel As Integer)
Static Started As Boolean                            
If Not Started Then                                  
        AssignSubRecordSource me              
        Started = True                                
End If
End Sub

...and...this...

Private Sub Report_Open(Cancel As Integer)
        AssignSubRecordSource me            
End Sub
' *****

Regards
Bill

 

by: billcutePosted on 2006-09-12 at 16:13:54ID: 17507744

mbizub / Mike,
I tested both suggestions under Access 2K today and both suggested code returned a Run-time Error '2176':
"The settings for this property is too long"

on....
Private Sub Report_Open(Cancel As Integer)
   AssignRecordSource Me                               '<<--- Error line
End Sub

...and  on...

Private Sub Report_Open(Cancel As Integer)
   Me.RecordSource = MyRptYear1  &  MyRptYear2  &  MyRptYear3 &  MyRptYear4  &  MyRptYear5    '<<-- Error line
End Sub
' *******

Regards
Bill

 

by: billcutePosted on 2006-09-17 at 07:12:01ID: 17538272

mbizub / Mike,
Is it fair to conclude that there is no solution available to resolve the problem above. If so, then can I request to close this question and refund points?

Regards
Bill

 

by: MikeToolePosted on 2006-09-17 at 07:42:58ID: 17538350

Bill,
Sorry, I've been out of the loop for a few days.
So far we've been trying to fix the problem without changing the approach too much. Another approach is to use your SQL to create an Access query, then use that as the record source for your report. A query can refer to controls in an open form the same way as in your SQL string:

And ((DatePart('yyyy', [PermitEDate])) =  [Forms]![Report Date Range]![input year]

 

by: billcutePosted on 2006-09-17 at 17:39:20ID: 17540322

Mike,
I didnt quite follow your suggestion on the SQL

Regards
Bill

 

by: billcutePosted on 2006-09-19 at 19:55:09ID: 17557835

Mike,
I will appreciate a clearer suggestion and how to implement it.

Regards
Bill

 

by: MikeToolePosted on 2006-09-20 at 00:50:51ID: 17558669

Bill,
Sorry for the delay.
What I mean is this...
Your code builds up a SQL string which it then assigns as the source for the report. There is nothing, so far as I can see, that that changes in the SQL apart from the value returned by the reference to the Input Year on the form. This means that the same SQL string could be used in an Access query as follows:
- Create a new Query in design view
- Close the Show Table dialog without selecting a table
- Choose the SQL view from the View combo-box on the left end of the design toolbar
- Paste your query string into the sql edit box that is displayed, overwriting what's already there (it should just contain SELECT;)

The only difference between the dtring you built-up in your code and what you need to paste-in here is that [Forms]![Report Date Range]![input year] needs to be a literal in the string itself, rather than a value concatenated at run-time. (I've pasted the string at the end of this post)

- Save the query using a name of your choice - let's say qryReport
- Use qryReport as the source of your report

Note: the query will only work when the form Report Date Range is open - it needs to get the year criteria from there

Hope this helps,
Mike

The string should look like this:
SELECT tblTPlant.TPlant AS TPlantID, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=1 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ1, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=1,[SanFlow],0))AS [San FlowQ1], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=1 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ1, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=1,[PlugFlow],0)) AS [Plug FlowQ1], ([San FlowQ1]*0.65)-([Plug FlowQ1]*0.65) AS [Net FlowQ1], Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=2 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ2, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=2,[SanFlow],0))AS [San FlowQ2], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=2 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ2, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=2,[PlugFlow],0)) AS [Plug FlowQ2], ([San FlowQ2]*0.65)-([Pl
ug FlowQ2]*0.65) AS [Net FlowQ2],Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ3, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=3, [SanFlow],0))AS [San FlowQ3], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ3, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=3,[PlugFlow],0)) AS [Plug FlowQ3], ([San FlowQ3]*0.65)-([Plug FlowQ3]*0.65) AS [Net FlowQ3],Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.SanFlow<>0)),1,0)) AS NCCountQ4, Sum(IIf([SConnTypeID]='NC' And DatePart('q',[permitedate])=4,[SanFlow],0))AS [San FlowQ4], Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=4 And IsNull([SID])=False And ((tblSewer.PlugFlow<>0)),1,0)) AS PLCountQ4, Sum(IIf([SConnTypeID]='PL' And DatePart('q',[permitedate])=4,[PlugFlow],0)) AS [Plug FlowQ4], ([San FlowQ4]*0.65)-([Plug F
lowQ4]*0.65) AS [Net FlowQ4] FROM tblTPlant INNER JOIN tblSewer ON tblTPlant.TPlantID = tblSewer.TPlantID WHERE (((tblSewer.SewerTypeID) = 'SA' Or (tblSewer.SewerTypeID) = 'CM') And ((DatePart('yyyy', [PermitEDate])) = [Forms]![Report Date Range]![input year] ) And ((tblSewer.TPlantID) Is Not Null) And ((tblSewer.PermitEDate) Is Not Null) And ((tblSewer.CIDate) Is Not Null) And ((tblSewer.PermitNo) Is Not Null)) GROUP BY tblTPlant.TPlant;



 

by: billcutePosted on 2006-09-20 at 03:26:48ID: 17559286

Mike,
Sorry...that I did not understand you earlier. I already have an SQL version. What I am trying to do is to hide the sql string behind a report -- the reason I went through the other procedure that is not working.

Regards
Bill

 

by: billcutePosted on 2006-09-21 at 16:07:57ID: 17573917

Mike,
Did you receive my last posted comment?

Bill

 

by: MikeToolePosted on 2006-09-22 at 00:05:48ID: 17575569

Bill,
OK, what is the aim of 'hiding the SQL behind the report'? Maybe there's another way to achieve it.
Otherwise I think that you should maybe cancel the question - I don't have any more ideas for your exact original question.
Regards,
Mike

 

by: billcutePosted on 2006-09-22 at 01:35:32ID: 17576097

Mike,
Thanks for your assistance

Regards
Bill

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...