Okay, so Peter Schroeder contributed a Serialize() function that returns the
AbsolutePosition of a record in a query.
I don't think that's a really useful generic solution because:
a) It handles a single criteria only.
b) It doesn't cope with additional filtering or sorting that the user may
apply to the query.
c) It may not yield the same results where a query's sort order is not
adequately defined.
d) It will be quite slow an inefficient for large queries, as it opens a
recordset for every record.
e) It will not work properly for parameter queries.
Write to a temp table with an AutoNumber if you want a serialized query.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users -http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
Thank you for your reply. I guess I misread the example, but there is
a query in there
with an expression pointing to:
Expr1: Serialize("query1","code",
Code:
)[/QUOTE]
[QUOTE]
and a Module:[/QUOTE]
[QUOTE]
'Stephen Lebans April 1999
'For use directly as a calculated expression in the query
'For demonstration purposes only
'See my posting comp.databases.ms-accessfor an adapted version of this
function
'to be used on a form in an unbound text box www.Dejanews.comsearch
Lebans query
'Blatantly adapted from Microsoft source code
'ACC: How to Display Line Numbers on Subform Records Article ID:
Q120913
'Sorry, recordset property of Screen.ActiveDatasheet is not available
'In query design view save any changes to your query to disk before
executing your query
'Only send an indexed field to the function[/QUOTE]
[QUOTE]
Function Serialize(qryname As String, keyname As String, keyvalue) As
Long
Dim dbs As Database
Dim rs As Recordset[/QUOTE]
[QUOTE]
Set dbs = CurrentDb
On Error GoTo Err_Serialize
Set rs = dbs.OpenRecordset(qryname, dbOpenDynaset, dbReadOnly)[/QUOTE]
[QUOTE]
On Error GoTo Err_Serialize[/QUOTE]
[QUOTE]
'Find the current record.
Select Case rs.Fields(keyname).Type
' Find using numeric data type key value?
Case DB_INTEGER, DB_LONG, DB_CURRENCY, DB_SINGLE, _
DB_DOUBLE, DB_BYTE
rs.FindFirst "[" & keyname & "] = " & keyvalue
' Find using date data type key value?
Case DB_DATE
rs.FindFirst "[" & keyname & "] = #" & keyvalue & "#"
' Find using text data type key value?
Case DB_TEXT
rs.FindFirst "[" & keyname & "] = '" & keyvalue & "'"
Case Else
MsgBox "ERROR: Invalid key field data type!"[/QUOTE]
[QUOTE]
End Select[/QUOTE]
[QUOTE]
Serialize = Nz(rs.AbsolutePosition, 0) + 1[/QUOTE]
[QUOTE]
Err_Serialize:
'Add your own Error handler
rs.Close
dbs.Close
Set rs = Nothing
Set dbs = Nothing[/QUOTE]
[QUOTE]
End Function[/QUOTE]
[QUOTE]
?????????- Hide quoted text -[/QUOTE]
- Show quoted text -[/QUOTE]
Thank you Allen, but since I have never written a "temp table", could
you provide some direction?