Question : Access Query Sequential Counter

I am trying to add a expression field into a query that assigns a sequential number to each record. for ex. the first record will be assigned 1 and then the second record would be assigned 2 and etc. This will always be the same when I run this query no matter if it is new criteria or not.

Answer : Access Query Sequential Counter

Gary,

<>
 
  I have re-opened the question.
 
<>
 
  As I mentioned, the function will get called twice for each row if there is criteria on the column.  

  Add this to your module:

Global glngGetLineCounter2 As Long
Global gintGetLineCounterFlag2 As Integer

Sub GetLineCounter2Reset()

  glngGetLineCounter2 = 0
  gintGetLineCounterFlag2 = False
 
End Sub
Function GetLineCounter2(varName As Variant) As Long

  If gintGetLineCounterFlag2 = True Then
    glngGetLineCounter2 = glngGetLineCounter2 + 1
    gintGetLineCounterFlag2 = False
  Else
    gintGetLineCounterFlag2 = True
  End If

  GetLineCounter2 = glngGetLineCounter2

End Function


   and call GetLineCounter2 instead of GetLineCounter.


<>
 
That's the reason I asked what it's going to be used for.  You can't scroll though the records with this technique.  When you do that, the row is being fetched again and any functions in it are called again.

  There are different techniques based on how your going going to use the result set.   What works no matter what would be adding a column to the table called LineNumber, and using GetLineCounter() as part of an update query before using the table.

  In a report  you can add a text control, set it's default value to 1, and change it's running sum to "over all"

 Let me know what you need if anything else...
JimD.
 
Random Solutions  
 
programming4us programming4us