You can open the data in a private datasession. Instead of a UDF, create an object based on Session (VFP6SP3 or later), or on Form (which doesn't need to be made visible).
If you want to call the function as a function, you can invoke the Session or Form object from the function.
>I have a function like the following, used to get the total for a single invoice.
>
>PROCEDURE GetInvoiceTotal()
>This.SelectAlias("Invoice")
>SUM Amount TO Total
>RETURN Total
>
>
>Now, I want to call GetInvoiceTotal() from a global object, and specify the invoice it should total. If I change the function to the one below,
>
>PROCEDURE GetInvoiceTotal(InvoiceID)
>This.GetInvoiceLines(InvoiceID)
>This.SelectAlias("Invoice")
>SUM Amount TO Total
>RETURN Total
>
>the problem is that GetInvoiceLines() by definition reloads the Invoice cursor, destroying any pending changes. This means I can't use it within the context of a single invoice anymore.
>
>I need to be able to total an invoice in progress without losing changes, but I'd also like to be able to total a specified invoice at will. What's the easiest/best way to get the best of both worlds?
>
>Chris.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)