MultiPage exit/change event

P

Patrick Simonds

I use a MultiPage control to gather data and have it placed on my
worksheets. I have code which causes the data to be placed on the worksheet
when you exit one (of 10) TextBox for another, my problem is if the user
clicks on the next page of the MultiPage control, Excel does not recognize
it as an exit event from a TextBox. So the value is not placed on the
worksheet.

I used this approach (as opposed to just placing the data on the worksheet
upon closing the UserForm,which is easy) because I have a TextBox on the
UserForm which must be updated as numbers are entered. Now someone suggested
that I use the code below.

As you can see I want to apply this code to MultiPage2. I tried many
variants of the suggested code, but was not able to get more than the first
page to update when I clicked to another page. MultiPage2 control has 6
pages (January, February, March, April, May, June). This is where I am now,
but again it only works when I click from January to any of the other pages.

Proposed code:

Private Sub YourMultiPage_Change()
If MultiPage.Value = 0 Then 'First Page
'TextBox handling here
End If
End Sub



Adapted Code:

Private Sub MultiPage2_Change()

If MultiPage2.Value = 0 Then
PopulateWorksheets.PopulateWorksheets

ElseIf MultiPage2.Value = 1 Then
PopulateWorksheets.PopulateWorksheets

ElseIf MultiPage2.Value = 2 Then
PopulateWorksheets.PopulateWorksheets

ElseIf MultiPage2.Value = 3 Then
PopulateWorksheets.PopulateWorksheets

ElseIf MultiPage2.Value = 4 Then
PopulateWorksheets.PopulateWorksheets

ElseIf MultiPage2.Value = 5 Then
PopulateWorksheets.PopulateWorksheets

End If

End Sub
 
S

stevebriz

Patrick
if you want it update when you change any to any page.you dont need:
If MultiPage.Value = 0 Then

eg:
Private Sub YourMultiPage_Change()

End Sub
for MultiPage2
you don't need more than...if it applies to all pages

Private Sub MultiPage2_Change()
PopulateWorksheets.PopulateWorksheets
End Sub

let me know if I misunderstood...HTH
 
T

Tom Ogilvy

I set up you situation and modified you code slightly

Private Sub MultiPage2_Change()

If MultiPage2.Value = 0 Then
MsgBox "Page is 0"

ElseIf MultiPage2.Value = 1 Then
MsgBox "Page is 1"

ElseIf MultiPage2.Value = 2 Then
MsgBox "Page is 2"

ElseIf MultiPage2.Value = 3 Then
MsgBox "Page is 3"

ElseIf MultiPage2.Value = 4 Then
MsgBox "Page is 4"

ElseIf MultiPage2.Value = 5 Then
MsgBox "Page is 5"

End If

End Sub

worked as expected for me.

If the code you show is your actual code, then how does
PopulateWorksheets.PopulateWorksheets know what to do. There is no use
using your if/elseif construct if you issue the same exact command in each
one. If the PopulateWorksheets code is smart enough to check which page is
active, then you don't need the If statements.

Also, you are getting the page that was activated, not the page that was
departed.

Another problem is that if the User selects something else (the other
multipage or somewhere else on the userform), you don't trigger this event.

I think you will need to sense when the user is moving away from the current
page.

Private Sub MultiPage2_MouseMove(ByVal Index As Long, ByVal Button As
Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Application.StatusBar = MultiPage2.Value & " x: " & X & " y: " & Y
End Sub

will show you that the mousemove event fires continuously as you move the
mouse over the page. (the display is in the statusbar - make sure it is
visible). In that event, you can compare the x and y locations to the
boundaries toward the edges of the page. If the user goes outside that
boundary, then you can perform your "exit" actions. Use a public variable
with the enter events of the textboxes to hold information on which textbox
was entered. Then reset it in the exit event. If the user approaches the
boundary and this variable is set, then clear the variable and perform the
"exit" action.

This concept would replace your current concept.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top