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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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]
 
Upvote 0
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.:)
 
Upvote 0

Forum statistics

Threads
1,222,900
Messages
6,168,926
Members
452,227
Latest member
sam1121

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