ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Check for any data changes in a form with multipage object (https://www.excelbanter.com/excel-programming/311266-check-any-data-changes-form-multipage-object.html)

Bert Neuenschwander

Check for any data changes in a form with multipage object
 
Ive created a form containing a multipage form. Each page of the form
contains multiple text boxes for user input. Prior to the user clicking to
go to another page of the form, Id like to do some validating . I know I
could use the €śon Exit€ť event for each text box, but prefer instead to
trigger based on trying to exit the page.

Ideas?
Thanks,
Bert


sebastienm

Check for any data changes in a form with multipage object
 
You could use the _Change event, do something like the following:
- mProcessing -- boolean: variable to track when we are checking a Page
validation during the Change event.
- bValidated -- boolean : variable to track if valiudation fails or not.
During the Change event (the new page is already activated), if the
validation fails on the oldPage, the old page needs to be re-activated
programmatically. The sideeffect is that it triggers the Change event again
for a case where we don't want to check validation (we are just setting the
active page back). This is why we use the mProcessing variable, to keep track
of that case. It is similar to the _Change event of a Sheet.... it is common
practice to set Application.EnableEvents to False, process the event, then
setting it back to True)
Regards,
Sebastien

'--------------------------------------------------
' In Userfform

Private mProcessing As Boolean
Private oldPage As Page

Private Sub MultiPage1_Change()
Dim newPage As Page
Dim bValidated As Boolean

If Not mProcessing Then 'if we are not already processing it
mProcessing = True
Set newPage = MultiPage1.SelectedItem

'Check validation of the oldPage
If oldPage Is Nothing Then
bValidated = True
Else
'----- ADD CODE HERE ---------
'Validation code of oldPage
'bValidated=????
End If

If Not bValidated Then 'Set back the old page
MultiPage1.Value = oldPage.Index
Else 'keep new page on
Set oldPage = newPage
End If

'Finish processing change event
mProcessing = False
End If
End Sub

Private Sub UserForm_Initialize()
Set oldPage = MultiPage1.SelectedItem
End Sub
'----------------------------------------------------------------
"Bert Neuenschwander" wrote:

Ive created a form containing a multipage form. Each page of the form
contains multiple text boxes for user input. Prior to the user clicking to
go to another page of the form, Id like to do some validating . I know I
could use the €śon Exit€ť event for each text box, but prefer instead to
trigger based on trying to exit the page.

Ideas?
Thanks,
Bert


sebastienm

Check for any data changes in a form with multipage object
 
by the way, by exiting the page i assumed you meant when you click another
page of the multipage.
Seb

"sebastienm" wrote:

You could use the _Change event, do something like the following:
- mProcessing -- boolean: variable to track when we are checking a Page
validation during the Change event.
- bValidated -- boolean : variable to track if valiudation fails or not.
During the Change event (the new page is already activated), if the
validation fails on the oldPage, the old page needs to be re-activated
programmatically. The sideeffect is that it triggers the Change event again
for a case where we don't want to check validation (we are just setting the
active page back). This is why we use the mProcessing variable, to keep track
of that case. It is similar to the _Change event of a Sheet.... it is common
practice to set Application.EnableEvents to False, process the event, then
setting it back to True)
Regards,
Sebastien

'--------------------------------------------------
' In Userfform

Private mProcessing As Boolean
Private oldPage As Page

Private Sub MultiPage1_Change()
Dim newPage As Page
Dim bValidated As Boolean

If Not mProcessing Then 'if we are not already processing it
mProcessing = True
Set newPage = MultiPage1.SelectedItem

'Check validation of the oldPage
If oldPage Is Nothing Then
bValidated = True
Else
'----- ADD CODE HERE ---------
'Validation code of oldPage
'bValidated=????
End If

If Not bValidated Then 'Set back the old page
MultiPage1.Value = oldPage.Index
Else 'keep new page on
Set oldPage = newPage
End If

'Finish processing change event
mProcessing = False
End If
End Sub

Private Sub UserForm_Initialize()
Set oldPage = MultiPage1.SelectedItem
End Sub
'----------------------------------------------------------------
"Bert Neuenschwander" wrote:

Ive created a form containing a multipage form. Each page of the form
contains multiple text boxes for user input. Prior to the user clicking to
go to another page of the form, Id like to do some validating . I know I
could use the €śon Exit€ť event for each text box, but prefer instead to
trigger based on trying to exit the page.

Ideas?
Thanks,
Bert



All times are GMT +1. The time now is 12:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com