Solved

Serialize using Subquery

Posted on 2010-09-14
7
626 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
  • 4
  • 2
7 Comments
 
LVL 46

Author Comment

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

Expert Comment

by:Rey Obrero
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 49

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 49

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…

919 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now