[AccessD] Query Line Numbers

Gustav Brock Gustav at cactus.dk
Tue Mar 29 09:11:37 CST 2005


Hi Keith

Also, if you should ever need to browse these row numbers:

Public Function RowCounter( _
  ByVal strKey As String, _
  ByVal booReset As Boolean) As Long
  
' Builds consecutive RowIDs in select, append or create query
' with the possibility of automatic reset.
'
' 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().

  Static col As New Collection
  
  On Error GoTo Err_RowCounter
  
  If booReset = True Then
    Set col = Nothing
  Else
    col.Add Str(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

/gustav

>>> kwilliam at ashlandnet.com 03/29 4:48 pm >>>
Thanks, guys.  I'll give these a try!!




More information about the AccessD mailing list