VBA to Close forms

satty

Board Regular
Joined
Jan 12, 2003
Messages
68
Hey people!

i have many forms within my access database. instead of using the buttons and macros to navigate, i have used images. however, i was wondering:

- if i could use VBA to just that just closes the form. i dont want to have to create a macro for each button to close different forms.

Something like Form.Quit or something. is this possible? basically one VBA code that will close any form when the button is clicked.

Thanx Guys
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
The VBA command to close the active window is
DoCmd.Close
Put this on the ON Click Event for the button in the code module behind the form.

HTH

Peter
 
Upvote 0
You will need to do this in a Standard Module and pass the form argument from your form-level modules:

In the Standard Module:
Code:
Public Function Close_Form(strForm as Form)
DoCmd.Close AcForm, strForm
End Function

In the Module of every form that you'd like to close
Code:
Your_Button_On_Click()
Call Close_Form(Me)
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,574
Messages
6,160,602
Members
451,657
Latest member
Ang24

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top