There are roughly two parts to the use of Access databases. One is the calculation and processing of data. Data tables and queries are all used to complete data processing. They will complete the calculation and processing of data according to our needs to form data information. For reference; the second is the production of user interface (UI). Although this part is not the core, it is also very important. Because for ordinary users, they don’t know how to create queries and other tasks. All they need is to click a button to get the necessary information. Therefore, we need to create a large number of forms to guide users to perform database operations. to get the information they need. Therefore, for a good database application system, these two parts are indispensable.
In the process of building a form and guiding users to use it, we often encounter this problem: sometimes the user presses a command button, and when the program starts to execute the program associated with that button, due to the large amount of calculation work involved, Therefore, the computer will run slower, and the screen will appear unresponsive in Access. If it takes a little longer, it will make people feel like it has crashed? Therefore, in this case, it would be better if there is a prompt box to tell the user what the computer is doing at this time. In addition, it can also make the time feel shorter, because waiting without any changes will make people feel longer!
To complete this instant information display window, the first thing we think of is to add a piece of code to a certain part of the program. This code opens a new window with relevant text in the window, such as "The program is running, please wait..." "Wait, the code is also very simple, in Access it is
…
DoCmd.OpenForm "wait"
Forms!Wait!lblwait.Caption = "The program is running, please wait..."
…
Among them, wait is the name of the form (Form), lblwait is the name of a label (Label) control in the form. When the program runs to the ellipsis, the wait window will be opened, and then the name of the label control will be changed to "The program is running" Running, please wait...".
But when you actually run this program code, you will find that the effect is not what you imagined. The wait window does come out, but it is just a white area without any text. At first, you may think that your computer is running slowly and the display It doesn't work, but even if you switch to the fastest computer to run it, the result will still be like this. Isn't it depressing? !
At this time, it’s the Repaint method’s turn to show its talents. Modify the above code slightly, as follows:
…
DoCmd.OpenForm "wait"
Forms!Wait!lblwait.Caption = "The program is running, please wait..."
Forms!Wait.Repaint
…
Run it again and you will see the window displays normally and prompts.
After that, you can add this code wherever needed, change the text, and you can prompt the user in real time what the program is doing while the program is running!
The reason is actually very simple, that is, during the running of the program, the screen display will not be updated in real time, which will speed up the running of the program. Therefore, when a large number of calculations are designed, the program will not have any display updates, as if it has crashed. , but adding the Repaint method will force the screen display to be updated, allowing us to dynamically see the running status of the program.