Reset Page every click

Asked

Viewed 48 times

0

inserir a descrição da imagem aqui Have in the figure above this small Userform with three pages. On the first page, when clicking the Enable button, the next date is inserted with Textbox Data as False, so that the user does not change. The Enable button also enables the Expected Textbox and the Insert and Clear buttons. By clicking on the second page, I have another setting, of course, and I can enter updated data. When clicking again on the first page, if the user has not taken any action by clicking the Enable button, I would like the page to return to its original state. I’m using this code, and I’d like to know if it’s really like this. I will use for the three pages.

Private Sub MultiPage1_Click(ByVal Index As Long)
    With Me.MultiPage1
        If .Value = 0 Then Call Me.RestauraControles0
        If .Value = 1 Then Call Me.RestauraControles1
    End With
End Sub

Me.Restauracontroles0 clears all and leaves enabled only the Enable button.

  • RestauraControles0 this is a function within the form or a module?

  • Restorcontroles0 is inside the form. Simply leave enabled only the Enable button.

  • 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.

  • Restauracontroles1 does the same by clicking on the second page. Or should.

  • 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

1 answer

0

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
  • Thank you very much!

  • @Paulosemblano You can also use as a generic function to "reset" each desired page... Instead of using the event MultiPage1_Change

  • In function I shuffle a little. Rsrsrsrsrs

Browser other questions tagged

You are not signed in. Login or sign up in order to post.