How can I modify the following code to add a row number in the query, now that the data source 'packing_ship_mark_1a' has been changed from a table to a query, so it can run correctly?
Code:
Public Function fnRank1(ByVal id As Long) As Long
'
' put the Linked table name here and replace dbo_table_1
'
Const the_linked_table As String = "packing_ship_mark_1a"
Static d_obj As Object
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim i As Long
' note to reset this function pass 0 or negative value to the function
If id < 1 Then
Set d_obj = Nothing
Exit Function
End If
If (d_obj Is Nothing) Then
Set d_obj = CreateObject("scripting.dictionary")
Set db = CurrentDb
Set rs = db.OpenRecordset(the_linked_table, dbOpenSnapshot, dbReadOnly)
With rs
If Not (.BOF And .EOF) Then
rs.MoveLast
rs.MoveFirst
End If
Do Until .EOF
i = i + 1
d_obj(!id & "") = i
.MoveNext
Loop
.Close
End With
End If
fnRank1 = d_obj(id & "")
End Function