• Functions in Queries (A2K SR1)

    Author
    Topic
    #363694

    Hello.

    I’ve not done a great deal of A2K development, but I have done quite a bit under A97. I’ve got an A2K database converted from A97 and a number of the queries are running really slowly now. I’ve pinpointed the problem to be a change in the way A2K handles functions called from queries. Under A97, if you called a function from a query and didn’t pass it any field values from the query it was called once only, under A2K it seems to call the function once per record.

    I’ve looked through Help and also MSDN and the only concrete thing I’ve found was a knowledge base article titled “ACC2000: Number of Times a Custom Function Runs in a Query” (Q210554). Unfortunately this confirms what I was expecting (that the function should only be called once per query execution) not what seems to be happening (once per record). I’ve tried the example in the article in case something really odd was happening in my real application, but it exhibits the same behaviour.

    To save anyone looking, this is the query and the function from the MSDN article. It uses the Northwind sample DB.

    SELECT Employees.LastName, ShouldIncrement() AS RecordNumber FROM Employees;

    Global RecordNum

    Function ShouldIncrement()
    RecordNum = RecordNum + 1
    ShouldIncrement = RecordNum
    End Function

    The example shows the query returning 1 in the RecordNumber field for each record where in fact it returns a different value for each record. Is this a bug? A new feature? Is there some setting I can turn off? Any other simple workaround?

    Thanks in advance,

    Simon.

    Viewing 0 reply threads
    Author
    Replies
    • #555808

      All I can say is that it gives me the same results in Access 2000 SR1 as well, in spite of what the MSKB article says. Both Example A and Example B are running once for each record.

      There are a couple of things besides that which can slow down execution in Access 2000, though. One is running against an Access 97 back end, which is horribly slow. So if you have a split database, make sure the back end got converted as well.

      Another is subdatasheets, which seem like a good idea but perform miserably and slow down the entire database, especially if you combine them with lookup fields in your tables or combobox lookups on your forms. Subdatasheets have to be turned off one table at a time for each database, but there is code in the help files to do this.

      Finally, be sure to turn off Name Autocorrect for each database, both logging and tracking, from the Tools–>Options–>General tab. The latter won’t change the way your queries are behaving, but it will prevent some other problems from biting you when you least expect them.

      • #555852

        Charlotte,
        I just ran that function in a query in a test database (I’d never really thought about this before so I was curious) and the shouldincrement function returned 1 for every record. I’m running A2K (9.0.3821 SR1) on Win2k (SP2 as best I recall).
        There’s nothing like consistency. doh

        • #555881

          Rory, I think we may be onto something here. I just ran it on my laptop (same Access and Win2K as you) and it behaved as the article indicated it would. However, on my machine at work, where I only have SP1 on Win2K, I saw the behavior that Simon described. That suggests it’s a Win2k problem.

          • #555972

            Oooh, that’s interesting. On my main development machine I’m running A2K (9.0.3821 SR1) and Win 2K (SP1). On my other (standalone) PC I’m running A2K with no service packs installed and Win 2K (SP2). The query runs as it should on my other machine. I wanted to upgrade my other PC to A2K SR1 (just to prove to myself that it isn’t a difference in the query results in different Access versions), but I can’t seem to download the right set of files (I can’t use the standard online installation on my other PC as it has no internet connection).

            Most irritatingly, I can’t upgrade my main PC to W2K SP2. I’ve tried and I always get problems – particularly with the Search for Files and Folders functionality.

            Most PCs that will run my Access application are using NT 4 Workstation, so hopefully the problem won’t occur there either. Thanks for your help.

            Simon

          • #558468

            Charlotte – looks like it was resolved here.

            (My first post in Access!)

    Viewing 0 reply threads
    Reply To: Functions in Queries (A2K SR1)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: