Página 1 de 1

Formatar Textbox na condição "0000000-00"

Enviado: 24 Abr 2023 às 18:08
por Albino10
Senhores tentei e continuo tentando formatar uma caixa de Textbox para que após digitar 7 números surja "-" para depois digitar mais números (ex: 000100-23), sendo que eu digitaria somente os números (ex: 000010023), segue abaixo uma da minhas tentativas, eu errei tudo ou o que deve ser corrigido?
Private Sub Txt_NºProcesso_Cob_Change()
On Error GoTo Erro
On Error Resume Next
If tecla = 8 Then
Exit Sub
End If
Format (Me.Txt_NºProcesso_Cob.Value = "0000000-00")

If Len(Txt_NºProcesso_Cob.Value) = 7 Then
Me.Txt_NºProcesso_Cob.Value = Txt_NºProcesso_Cob.Value & "-"
Me.Txt_NºProcesso_Cob.Value.SelStart = 4
ElseIf Len(Txt_NºProcesso_Cob.Value) = 5 Then
Me.Txt_Cliente_Cob.SetFocus
End If

Exit Sub
Erro:
MsgBox "Erro!", vbCritical, "FORMATAR"

End Sub

Re: Formatar Textbox na condição "0000000-00"

Enviado: 25 Abr 2023 às 08:06
por Foxtri
Bom dia.
veja se serve.
Private Sub Txt_NºProcesso_Cob_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If Not IsNumeric(Chr(KeyAscii.Value)) Then
'If Not IsNumeric(Chr(KeyAscii.Value)) Or Len(Txt_NºProcesso_Cob.Text) >= 10 Then PARA LIMITAR EM MAIS DOIS NUMEROS APÓS O -
KeyAscii.Value = 0
Else
If Len(Txt_NºProcesso_Cob.Text) = 7 Then
Txt_NºProcesso_Cob.Text = Txt_NºProcesso_Cob.Text & "-"
End If
End If
End Sub

Até
Foxtri

Re: Formatar Textbox na condição "0000000-00"

Enviado: 26 Abr 2023 às 12:05
por Albino10
PERFEITO AMIGO!! muito obrigado pela ajuda.
Show!