Open Blank Form When Database is Opened, Access VBA

Previously in the article Open Form When Database is Opened, Access I’ve explained how you can cause a form to appear every time the an Access file is opened. By default the form will be displaying the first record in the table:
Default
In this article I will explain how you can cause a blank form to appear rather than a form with data from the first record.


Step 1:

Open the form in design view:
Result


Step 2:

Click on the View Code button on the Design ribbon:
View Code
The following window will open:
VBA Editor


Step 3:

If no previous macros have been written you will only see one class in the project explorer on the left:
Form_Form1

If there are multiple classes on the left click on the forms class. It will have a name in the format:

  • Form_“FormName”

where “FormName” is the name of the form, which in our case is “Form1”.

Write the following code inside the Form_Form1 class:

Private Sub Form_Load()
Call DoCmd.GoToRecord(, , acNewRec)
End Sub

VBA Code


Result:

Whenever the Access file is opened, a blank form will appear ready to input a new record:
Result

You can download the sample file and code used in this article from the link below:

See also:

If you need assistance with your code, or you are looking for a VBA programmer to hire feel free to contact me. Also please visit my website www.software-solutions-online.com

Leave a Reply

Your email address will not be published. Required fields are marked *

Search