Open and Close Form by VBA in Microsoft Access

Hi,dear MS Access learners! Generally we use micro for open and close our form but Some times we have  need to open or close form by clicking button, image or anything else by VBA code. In this topics I’ll show you how to open form and how to close form by clicking a button.

Suppose You are in a form now, name is FormA, there is a button btnA.  You wanna that, when user click on btnA then FormB will open.

Procedure : Open FormA and right click on btnA and go to properties , click on event tab then choose the on click event. Make the event with code builder and  write the code following the syntax below.


Code syntax for open form:

DoCmd.OpenForm “Your_form_name”

So we have to write this code for our example : DoCmd.OpenForm “FormB”

Code syntax for close form:

DoCmd.Close  acForm, “Your_form_name”

So we have to write this code for our example : DoCmd.Close  acForm, “FormB”

If you wanna close the current form  just write this code : DoCmd.Close

here you don’t have to need the mention the form name

NB: When you open or close any specific form you have to use the form name accurately. So be careful about the form name and keep form name accurate in your code.

Tags : , , , , , , ,

Share on :

Leave a Reply

+ one = 8