How can I have this code run faster?

Lopez, Ahiezer 236 Reputation points
2024-07-10T17:27:48.5333333+00:00

I have this code that is executed only when I open a form. I press a button that runs a macro and that macro simply opens the form. Once this form is opened, the code in the "On Load" event is triggered, this code can be seen below. This code calls on two different functions each used to calculate the deadlines using a table that has the company holidays.

The code all in all takes about 7 minutes to open, and thats with the form only having 13 records in it. How can I make this code execute faster?

By the way, the Access database is linked to an SQL server so the tables come from an SQL server.

The code was attached as a text file because the format of the code was getting messed up in the question.

User's image

User's image

Code.txt

Access
Access
A family of Microsoft relational database management systems designed for ease of use.
341 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
857 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. AlphonseG 201 Reputation points
    2024-07-11T18:57:16.68+00:00

    You are opening an entire SQL Server table (or whatever), walking through each row then for each, opening multiple separate recordsets, then updating each record.

    This is a classic definition of SLOW CRAWL.

    Don't see why all of these updates should be necessary every time the form is open.
    First, I would question the database design.
    Next, all of whatever processing is necessary should be moved to the server and done in a bulk/batch process. NOT row by row.

    You will need to provide much more detail.

    1 person found this answer helpful.

  2. Karl Donaubauer 1,726 Reputation points MVP
    2024-07-11T11:34:10.2533333+00:00

    Hi,

    You don't show us the VBA code to see if there's anything that might last 7 minutes.

    Probably more important would be to know your Access version and build number (see File - Account) because there's a recent/current bug that causes performance problems.

    Servus
    Karl


    Access News
    Access Forever
    Access DevCon
    Access-Entwickler-Konferenz AEK