Notifications
Clear all

Botão salvar com erro

2 Posts
2 Usuários
0 Reactions
679 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Colegas boa tarde.
Na planilha abaixo preciso que ao clicar no botão salvar se algum textbox não for preenchido ele não salve na planilha.
Do jeito que esta, mesmo quando avisa que não foi preenchido um textbox esta sendo salvando na planilha.

 
Postado : 07/05/2018 10:46 am
(@klarc28)
Posts: 0
New Member
 
Public Sub enumeraid()

   If IsNumeric(ActiveCell.Offset(-1, 0)) Then
      ActiveCell = ActiveCell.Offset(-1, 0) + 1

Else

    ActiveCell = 1
    
    End If
    
End Sub

Private Sub botaosalvar_Click()
   
    
'Verifica se todos os textbox foram preenchidos

If numeronota.Text = Empty Then
    MsgBox "Número da nota não foi informado"
    numeronota.SetFocus
    Exit Sub
Else
End If

If dataentrada.Text = Empty Then
    MsgBox "A data entrada não foi informado"
    dataentrada.SetFocus
        Exit Sub

Else
End If

If fornecedor.Text = Empty Then
    MsgBox "O fornecedor não foi informado"
    fornecedor.SetFocus
        Exit Sub

Else
End If

If vlrcontabil.Text = Empty Then
    MsgBox "O valor contábil não foi informado"
    vlrcontabil.SetFocus
        Exit Sub

Else
End If

If ComboBox.Text = Empty Then
    MsgBox "O patrimônio não foi informado"
    ComboBox.SetFocus
        Exit Sub

Else
End If

If vlricms.Text = Empty Then
    MsgBox "O valor ICMS não foi informado"
    vlricms.SetFocus
        Exit Sub

    
Else
End If

   
   'Se algum textbox não foi preenchido não salvar
   
   'Somente continuar se todos os texbox foram preenchidos
    
   
   
   ActiveCell.Select
   
      
     Do
     If Not (IsEmpty(ActiveCell)) Then
        ActiveCell.Offset(1, 0).Select
        
        End If
     
     Loop Until IsEmpty(ActiveCell) = True
     
          
enumeraid
     
     ActiveCell.Offset(0, 1).Value = numeronota
     ActiveCell.Offset(0, 2).Value = dataentrada
     ActiveCell.Offset(0, 3).Value = fornecedor
     ActiveCell.Offset(0, 4).Value = CDbl(vlrcontabil)
     ActiveCell.Offset(0, 5).Value = patrimonio
     ActiveCell.Offset(0, 6).Value = CDbl(vlricms)
     ActiveCell.Offset(0, 8).Value = CDbl(parcela)
     
     
     

   numeronota = ""
   dataentrada = ""
   fornecedor = ""
   vlrcontabil = ""
   patrimonio = ""
   vlricms = ""
   parcela = ""
        
         
      
            
End Sub


Public Sub ProgressStyle5(Percent As Single)

    Dim strTemp As String
    Dim intIndex As Integer
    
    intIndex = Int(Len(labPg5a.Caption) * Percent)
    If intIndex > 0 Then
        strTemp = String(intIndex, "•") & String(Len(labPg5a.Caption) - intIndex, " ")
    Else
        strTemp = String(Len(labPg5a.Caption), " ")
    End If
    labPg5.Caption = strTemp
    
End Sub

Public Sub ProgressStyle6(Percent As Single)

    Dim strTemp As String
    Dim intIndex As Integer
    
    intIndex = Int((Percent * 100) Mod (Len(labPg6a.Caption) + 1))
    strTemp = String(Len(labPg6a.Caption), " ")
    If intIndex > 0 Then
        Mid(strTemp, intIndex, 1) = "•"
    End If
    labPg6.Caption = strTemp
    
End Sub

Private Sub botaosalvar_Enter()

   vlricms.BackColor = &H80000016

   Label6.Visible = True
   Label12.Visible = False
   
End Sub

Private Sub botaolimpar_Click()

   numeronota = ""
   dataentrada = ""
   fornecedor = ""
   vlrcontabil = ""
   patrimonio = ""
   vlricms = ""
   parcela = ""
   
   numeronota.BackColor = &H80000016
   dataentrada.BackColor = &H80000016
   fornecedor.BackColor = &H80000016
   vlrcontabil.BackColor = &H80000016
   patrimonio.BackColor = &H80000016
   vlricms.BackColor = &H80000016
   
   Label1.Visible = True
   Label7.Visible = False
   Label2.Visible = True
   Label8.Visible = False
   Label3.Visible = True
   Label9.Visible = False
   Label4.Visible = True
   Label10.Visible = False
   Label5.Visible = True
   Label11.Visible = False
   Label6.Visible = True
   Label12.Visible = False
      
   numeronota.SetFocus
   
End Sub

Private Sub botaofechar_Click()

   Unload Me
   'Application.Visible = True

End Sub



Private Sub numeronota_Change()

   'Comando para só aceitar números
   If Not IsNumeric(numeronota.Text) Then numeronota.Text = Empty

End Sub

Private Sub numeronota_Enter()

   numeronota.BackColor = &H80000005
   
   Label1.Visible = False
   Label7.Visible = True
   
End Sub

Private Sub dataentrada_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

    'Limita a Qde de caracteres
    dataentrada.MaxLength = 10

End Sub

Private Sub dataentrada_Enter()

   numeronota.BackColor = &H80000016
   dataentrada.BackColor = &H80000005
   
   Label1.Visible = True
   Label7.Visible = False
   Label2.Visible = False
   Label8.Visible = True
   
End Sub

Private Sub dataentrada_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)

Select Case Len(dataentrada.Value)

Case 2
dataentrada.Value = dataentrada.Value & "/"

Case 5
dataentrada.Value = dataentrada.Value & "/"

End Select

End Sub

Private Sub fornecedor_Enter()

   numeronota.BackColor = &H80000016
   dataentrada.BackColor = &H80000016
   fornecedor.BackColor = &H80000005
   
   Label1.Visible = True
   Label7.Visible = False
   Label2.Visible = True
   Label8.Visible = False
   Label3.Visible = False
   Label9.Visible = True
   
End Sub

Private Sub fornecedor_Change()

   'Comando para Letras maiúsculas
   fornecedor = UCase(fornecedor)
   
   'Comando para Letras minúsculas
   'fornecedor = LCase(fornecedor)
   
End Sub



Private Sub vlrcontabil_AfterUpdate()

   vlrcontabil = Format(vlrcontabil, "#,##0.00")

End Sub

Private Sub vlrcontabil_Change()

   'Comando para só aceitar números
   If Not IsNumeric(vlrcontabil.Text) Then vlrcontabil.Text = Empty

End Sub

Private Sub vlrcontabil_Enter()

   numeronota.BackColor = &H80000016
   dataentrada.BackColor = &H80000016
   fornecedor.BackColor = &H80000016
   vlrcontabil.BackColor = &H80000005
   
   Label1.Visible = True
   Label7.Visible = False
   Label2.Visible = True
   Label8.Visible = False
   Label3.Visible = True
   Label9.Visible = False
   Label4.Visible = False
   Label10.Visible = True
   
End Sub

Private Sub patrimonio_Enter()

   numeronota.BackColor = &H80000016
   dataentrada.BackColor = &H80000016
   fornecedor.BackColor = &H80000016
   vlrcontabil.BackColor = &H80000016
   patrimonio.BackColor = &H80000005
   
   Label1.Visible = True
   Label7.Visible = False
   Label2.Visible = True
   Label8.Visible = False
   Label3.Visible = True
   Label9.Visible = False
   Label4.Visible = True
   Label10.Visible = False
   Label5.Visible = False
   Label11.Visible = True

End Sub


Private Sub vlricms_AfterUpdate()

   vlricms = Format(vlricms, "#,##0.00")

End Sub

Private Sub parcela_AfterUpdate()

   parcela = Format(parcela, "#,##0.00")

End Sub

 Private Sub vlricms_Change()

   'Comando para só aceitar números
   If Not IsNumeric(vlricms.Text) Then vlricms.Text = Empty

   Dim V1 As Double

     If vlricms <> Empty Then
     V1 = CDbl(vlricms)
          End If

     parcela = Format(V1 / 48, "0.00")
     
End Sub
   
Private Sub vlricms_Enter()

   numeronota.BackColor = &H80000016
   dataentrada.BackColor = &H80000016
   fornecedor.BackColor = &H80000016
   vlrcontabil.BackColor = &H80000016
   patrimonio.BackColor = &H80000016
   vlricms.BackColor = &H80000005
   
   Label1.Visible = True
   Label7.Visible = False
   Label2.Visible = True
   Label8.Visible = False
   Label3.Visible = True
   Label9.Visible = False
   Label4.Visible = True
   Label10.Visible = False
   Label5.Visible = True
   Label11.Visible = False
   Label6.Visible = False
   Label12.Visible = True
   
End Sub

Private Sub UserForm_Initialize()

   UserForm2.Height = 317

   patrimonio.AddItem "MOLDE"
   patrimonio.AddItem "MÁQUINA"
   patrimonio.AddItem "EQUIP."
   
   Label7.Visible = False
   Label8.Visible = False
   Label9.Visible = False
   Label10.Visible = False
   Label11.Visible = False
   Label12.Visible = False
   'Application.Visible = False
   
End Sub


 
Postado : 07/05/2018 10:49 am