Microsoft Access Office VB VBA Help and Examples

Top Five One Line Code Statements

Here's a list of my five favorite one line code statements. Well worth reading through as these are things you only pickup from other programmers.

DoCmd.SetWarnings False

Switches of all warning messages. This is extremely useful when you are running a large number of update, or append queries in code. To switch warnings back on use
DoCmd.SetWarnings True

Application.Echo False

Switches off all screen updates. If you are doing something to all of your forms or reports you may want to switch off screen updates so the user doesn't see it, and it will run slightly faster. To switch the screen back on use
Application.Echo True

Dcount("Name","MSysObjects","[Name] = 'DatabaseObjectName'")

Returns 1 if the object specified by DatabaseObjectName exists in the current database. Saves having to loop through the collections just to find out if an object exists.

Screen.MousePointer = 11

If you are running a lengthy peice of code it's nice to inform the user that the application is busy. So use this to change the mouse pointer to an hourglass. To return the mousepointer to normal use
Screen.MousePointer = 0


Tells you what control had the focus just before the current one. Useful if you have to run code based on which box they were in but don't want to use lost focus. I use this for a special character paste function.

The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.