Help with VBA form

HDfatboy03

Board Regular
Joined
May 23, 2010
Messages
62
Hello

I have a 4 page form. After the user hits submit, the user would then hit next for the next form and so on. I am trying to write code to where, when the user clicks on next the next form appears and the previous form closes. This is what I have so far ... but doesn't seem to be working

CODE STARTS

Private Sub cmdNext2_Click()
frmApp3.Show
Unload Me
End Sub

CODE ENDS

Any help will be greatly appreciated

HDfatboy03
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

bertie

Well-known Member
Joined
Jun 12, 2009
Messages
1,869
Assuming you are using a MultiPage control for your user form you can use the page value for navigation. Remember that the base number of the control is zero, i.e.,
value = 0 is page 1
value =1 is page 2 etc.

Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] cmd[COLOR=red]Next[/COLOR]_Click()
   MultiPage1.Value = MultiPage1.Value [COLOR=red]+ 1[/COLOR]
   cmdPrevious.Enabled = [COLOR=darkblue]True[/COLOR]
 
   [COLOR=green]'reached the last page[/COLOR]
   [COLOR=darkblue]If[/COLOR] MultiPage1.Value = 3 [COLOR=darkblue]Then[/COLOR] cmdNext.Enabled = [COLOR=darkblue]False[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] cmd[COLOR=red]Previous[/COLOR]_Click()
   MultiPage1.Value = MultiPage1.Value [COLOR=red]- 1[/COLOR]
   cmdNext.Enabled = [COLOR=darkblue]True[/COLOR]
 
   [COLOR=green]'reached the first page[/COLOR]
   [COLOR=darkblue]If[/COLOR] MultiPage1.Value = 0 [COLOR=darkblue]Then[/COLOR]
      cmdPrevious.Enabled = [COLOR=darkblue]False[/COLOR]
      cmdNext.Enabled = [COLOR=darkblue]True[/COLOR]
   [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] UserForm_Initialize()
   cmdPrevious.Enabled = [COLOR=darkblue]False[/COLOR]
   cmdNext.Enabled = [COLOR=darkblue]True[/COLOR]
End [COLOR=darkblue]Sub[/COLOR]
 

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,329
Office Version
  1. 365
Platform
  1. Windows
HDfatboy03

The code works fine for me - where did you put it? How is it not working?

Any errors?

PS You might want to consider Bertie's idea of using a multipage - should be easier to work with than 4 different forms.:)
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,260
Messages
5,769,091
Members
425,516
Latest member
Melzebu

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
Top