Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing VBA forms in Excel

Status
Not open for further replies.

jdlandry3

Technical User
Jan 2, 2003
1
US
I have a very large spreadsheet created and have created numerous forms to complete information that will be input into the spreadsheet. My problem is that on each form, I need a "Back", "Cancel" and a "Next" button. I have the cancel and Next button working great, but can not find the code to close the previous form after I select the Next button. Also, when I click on the Back button, I need to recall the previous form. Does anyone know the code for these commands?
 
Two answers:

- consider using a multi-tab form, if you can make it work in your application. It gets all the information onto a single form, with random rather than sequential access. But it won't be the best solution if one form feeds off the information from the previous one, etc.

- if you want to stick with separate forms, I would use a master control sub outside of the userform code, which would consist of a select case statement inside a loop. The select case variable would be a public variable containing the number of the active form, say iForm.
In the nextbutton_click event, you would have
iForm=iForm+1
unload me
and similar code in the previous button handler.
Your main code would look something like

iForm=1
do
select case iForm
case 1: Form1.show
case 2: Form2.show
...
end select
loop until iForm>4
Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top