The code works the way you are doing, but if you want something more generic create a Class Module or do it the following way:
Since I don’t know how your entire form structure is and what you really want from page 2, this is an example to learn how to make loops in the form controls and generalize some tasks that can work on all pages.
Code
Option Explicit
Private Sub MultiPage1_Change()
Dim controle As Control
Dim pagina_atual As Long
Dim tudo_vazio As Boolean
tudo_vazio = True
With Me.MultiPage1
pagina_atual = .Value
For Each controle In .Pages(pagina_atual).Controls
If TypeName(controle) = "TextBox" Then
If Trim(controle.Value) <> "" Then
'Debug.Print controle.Name
tudo_vazio = False
Exit For
End If
End If
Next controle
If tudo_vazio Then
For Each controle In .Pages(pagina_atual).Controls
If TypeName(controle) = "CommandButton" Then
'Debug.Print controle.Name
If Not Trim(controle.Name) Like "*habilitar*" Then
controle.Enabled = False
End If
End If
Next controle
End If
End With
End Sub
Explanation
Where you loop the form controls of the current page and check for empty Text Boxes.
Current Page
The code pagina_atual = Me.MultiPage1.Value
returns the page value of the selected page.
Loop on the controls
For Each controle In Me.MultiPage1.Pages(pagina_atual).Controls
Next controle
Loop all controls on the selected page of the last page.
Check if it is text box
If TypeName(controle) = "TextBox" Then
End If
Checks if the control is a text box.
Check if something was written in the Text Box
If Trim(controle.Value) <> "" Then
End If
Checks if the value of the text box is different from empty.
If it’s not empty
tudo_vazio = False
Exit For
If the control is not empty, that is, with some value. Change the flag tudo_vazio
to False and exits the loop.
Checks the flag tudo_vazio
If tudo_vazio Then
End If
Case tudo_vazio
be true, continue with the code.
Loop controls and check button
The same way as before, the loop in the controls is reset and is checked if it is Rotary pushbutton.
Checks Command Button Name
As the Text_box are all empty, it means there has been no change. Then all buttons that do not contain the enabled word in the name will be disabled with controle.Enabled = False
If Not Trim(controle.Name) Like "*habilitar*" Then
End If
RestauraControles0
this is a function within the form or a module?– danieltakeshi
Restorcontroles0 is inside the form. Simply leave enabled only the Enable button.
– Paulo Semblano
Restorcontroles0 is inside the form. Simply leave only the Enable button enabled. Clears all the textbox controls of the first page. And that’s what I’m looking for: selected the first page, clear everything with Restorcontroles0.
– Paulo Semblano
Restauracontroles1 does the same by clicking on the second page. Or should.
– Paulo Semblano
Sub RestauraControles0()
 Me.tbData0.Enabled = True
 Me.tbData0.Text = ""
 Me.tbData0.Enabled = False
 Me.tbPrevisto0.Enabled = True
 Me.tbPrevisto0.Text = ""
 Me.tbPrevisto0.Enabled = False
 Me.btInserir0.Enabled = False
 Me.btLimpar0.Enabled = False
 Me.btHabilitar0.SetFocus
End Sub
– Paulo Semblano