Solved

Serialize using Subquery

Posted on 2010-09-14
7
634 Views
Last Modified: 2013-11-28
Hi experts,

Up till now I've been using Lebans Serialize function to add sequential numbers to my query.
For a particular query it was very slow, so I decided to take a different path. I use a subquery, & in the form it works fine...much quicker than the serialize function.
The trouble is when I try and view the query Access blows up/Closes down...no message.
Any ideas why it should work in a form, but not able to view it.
I can also view it in design mode.

Attached please find the query..It's based on many others..I can't post them all.

I'm using Access 2003 SP3 + latest hotfixes

Gary
SELECT o1.ContactID, (SELECT COUNT(contactid) FROM QryPreSubTotalFacility AS o2 WHERE o2.DueDate <=O1.DueDate) AS InstNo, o1.DueDate
FROM QryPreSubTotalFacility AS o1;

Open in new window

0
Comment
Question by:tbsgadi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 46

Author Comment

by:tbsgadi
ID: 33672033
BTW the same happens in Access 2007
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 33672688
1. convert the query QryPreSubTotalFacility to a make table query (this is just a test)
   * run a query with the count(*) subquery using the created table, see if you still get the problem

2. can you post the SQL of query QryPreSubTotalFacility
0
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points
ID: 33679624
Here is a very fast method using a Collection.
The in-line comments explain typical usage.

/gustav
Public Function RowCounter( _
  ByVal strKey As String, _
  ByVal booReset As Boolean, _
  Optional ByVal strGroupKey As String) _
  As Long
  
' Builds consecutive RowIDs in select, append or create query
' with the possibility of automatic reset.
' Optionally a grouping key can be passed to reset the row count
' for every group key.
'
' Usage (typical select query):
'   SELECT RowCounter(CStr([ID]),False) AS RowID, *
'   FROM tblSomeTable
'   WHERE (RowCounter(CStr([ID]),False) <> RowCounter("",True));
'
' The Where statement resets the counter when the query is run
' and is needed for browsing a select query.
'
' Usage (typical append query, manual reset):
' 1. Reset counter manually:
'   Call RowCounter(vbNullString, False)
' 2. Run query:
'   INSERT INTO tblTemp ( RowID )
'   SELECT RowCounter(CStr([ID]),False) AS RowID, *
'   FROM tblSomeTable;
'
' Usage (typical append query, automatic reset):
'   INSERT INTO tblTemp ( RowID )
'   SELECT RowCounter(CStr([ID]),False) AS RowID, *
'   FROM tblSomeTable
'   WHERE (RowCounter("",True)=0);
'
' 2002-04-13. Cactus Data ApS. CPH
' 2002-09-09. Str() sometimes fails. Replaced with CStr().
' 2005-10-21. Str(col.Count + 1) reduced to col.Count + 1.
' 2008-02-27. Optional group parameter added.

  Static col      As New Collection
  Static strGroup As String
  
  On Error GoTo Err_RowCounter
  
  If booReset = True Or strGroup <> strGroupKey Then
    Set col = Nothing
    strGroup = strGroupKey
  Else
    col.Add col.Count + 1, strKey
  End If
  
  RowCounter = col(strKey)
  
Exit_RowCounter:
  Exit Function
  
Err_RowCounter:
  Select Case Err
    Case 457
      ' Key is present.
      Resume Next
    Case Else
      ' Some other error.
      Resume Exit_RowCounter
  End Select

End Function

Open in new window

0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 46

Author Comment

by:tbsgadi
ID: 33680081
Cap I tried the temp Table & of course it worked fine.
The question still remains why does a query work within a form but doesn't display?
0
 
LVL 46

Author Closing Comment

by:tbsgadi
ID: 33680092
I've come across this code before, but never tried it,assuming (wrongly) that it wouldn't be any quicker than Serialize.
Thanks!
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 33680254
You are welcome!

/gustav
0
 
LVL 46

Author Comment

by:tbsgadi
ID: 33691324
FYI I've managed to make the original query work..it needed to have ORDER BY o1.DueDate ;
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question