VBA to close a form

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. Windows
I have a button that brings me to a different form. How do I close the current form where the button resides?

Code:
Private Sub cmdRFPMgr_Click()
   
    OpenThisForm "frmRFPManager", Me.NewIDforRFPManager

End Sub
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
I want to close frmPIDGenerator and then go to frmRFPManager all with the click of the button
 
Upvote 0
Seems like this works (just a quick guess on my part):
Code:
Private Sub Command0_Click()
    DoCmd.OpenForm "Form2"
    DoCmd.Close acForm, "Form1", acSaveNo
End Sub
 
Upvote 0
If the code is in the form you want to close you can use this.
Code:
DoCmd.Close acForm, Me.Name
 
Upvote 0
Thanks

What if I wanted it to also Refresh when the button was clicked?
 
Upvote 0
Hi, not sure what you mean. The newly opened form is refreshed (de facto, since you are just opening it). The closed form cannot be refreshed.
 
Upvote 0
Got it - me.Refresh

I was not trying to refresh the form I was opening. I wanted a global refresh because other forms could be open that contain data from the from I was closing.

I appreciate the help.
 
Upvote 0
I don't believe there is a global refresh. You'd have to refresh all open forms (one at a time, I mean). "Could be" is not very persuasive here. I wouldn't suggest doing this unless you need to - and even then, maybe you could instead set this up so you don't need to use refreshes this way.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,221,692
Messages
6,161,351
Members
451,697
Latest member
pedroDH

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