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
 

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
75,362
Office Version
365
Platform
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.:)
 

Forum statistics

Threads
1,082,126
Messages
5,363,318
Members
400,725
Latest member
excelingtolearn

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top