Formulário de Pesquisa e Registro

marcinhovn

20-09-2018 21:50:41

Olá Pessoal,

Como não tenho muito conhecimento em VBA, estou desenvolvendo o meu projeto baseado em exemplos que vou encontrando na internet.
Esse arquivo que disponibilizo em anexo, é um controle de uma facção de costura onde lanço todas as informações desde o recebimento dos lotes para produzir até a entrega e o fechamento do mês de trabalho.
Tenho várias dúvidas e vou expôr algumas... se alguém puder me orientar ficarei grato.

1- Tenho 2 campos no meu formulário onde digito Datas, porém ao registrar na planilha não vai no formato de data;

2- O mesmo acontece com os 3 campos que são para valores;

3- Meu formulário tem um botão de pesquisa e ele funciona legal (a pesquisa se dá pelo número do lote), porém quero que ao visualizar no formulário um lote que foi pesquisado, eu possa fazer alguma alteração e registrar na mesma linha onde as informações já se encontram, e não inserir em uma nova linha.


Por enquanto, é isso que preciso.


Desde já, agradeço.

Tov Elen Shau

21-09-2018 11:45:43

Colega

Bom dia
‘1 Primeiro adicione o código no seu frm_cadastro
‘Observação, altere as txtbox txt_valor_c_bonus e txt_valor_total_lote de acordo com o exemplo colocado na txt_valor

Private Sub txt_dt_rcbto_lote_Change()
txt_dt_rcbto_lote.MaxLength = 10 'Numero máximo de caracteres
'Formatar como Data
Select Case Len(txt_dt_rcbto_lote)
Case Is = 2
txt_dt_rcbto_lote = txt_dt_rcbto_lote & "/"
Case Is = 5
txt_dt_rcbto_lote = txt_dt_rcbto_lote & "/"
End Select
End Sub

Private Sub txt_dt_rcbto_lote_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Aceitar somente números
Dim xVal As String
xVal = "0123456789"
If InStr(xVal, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub

Private Sub txt_dt_dev_lote_Change()
txt_dt_dev_lote.MaxLength = 10 'Numero máximo de caracteres
'Formatar como Data
Select Case Len(txt_dt_dev_lote)
Case Is = 2
txt_dt_dev_lote = txt_dt_dev_lote & "/"
Case Is = 5
txt_dt_dev_lote = txt_dt_dev_lote & "/"
End Select
End Sub

Private Sub txt_dt_dev_lote_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
'Aceitar somente números
Dim xVal As String
xVal = "0123456789"
If InStr(xVal, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
End If
End Sub

Private Sub txt_valor_AfterUpdate()
With frm_cadastro.txt_valor 'Escolha um dos formatos de valores
'If IsNumeric(.Value) Then .Value = Format(.Value, "#,##0.00") '--------Formato de valores SEM o cifrão
If IsNumeric(.Value) Then .Value = Format(.Value, "R$ #,##0.00") '--------Formato de valores COM o cifrão
End With
End Sub

‘Depois altere no botão gravar a parte do código
'Carregar os dados digitados nas caixas de texto para a planilha
x = txt_dt_rcbto_lote.Value
y = Format(x, "dd/mm/yyyy")
ActiveCell.Offset(0, 0).Value = y
ActiveCell.Offset(0, 1).Value = txt_num_lote.Value
ActiveCell.Offset(0, 2).Value = txt_referencia.Value
ActiveCell.Offset(0, 3).Value = txt_cliente.Value
ActiveCell.Offset(0, 4).Value = txt_pedido.Value
ActiveCell.Offset(0, 5).Value = txt_qtde_rcbto.Value
ActiveCell.Offset(0, 6).Value = txt_descricao.Value
ActiveCell.Offset(0, 7).Value = txt_valor.Value
ActiveCell.Offset(0, 8).Value = txt_fornecedor.Value
ActiveCell.Offset(0, 9).Value = txt_nf_rcbto.Value

i = txt_dt_dev_lote.Value
j = Format(i, "dd/mm/yyyy")
ActiveCell.Offset(0, 10).Value = j

ActiveCell.Offset(0, 11).Value = txt_nf_dev.Value
ActiveCell.Offset(0, 12).Value = txt_qtde_dev.Value
ActiveCell.Offset(0, 13).Value = txt_cont_fornec.Value
ActiveCell.Offset(0, 14).Value = txt_bonus.Value
ActiveCell.Offset(0, 15).Value = txt_valor_c_bonus.Value
ActiveCell.Offset(0, 16).Value = txt_valor_total_lote.Value


‘A respeito da necessidade número 3, de alteração. O Ideal seria que você tivesse um formulário para alterações. Mas você pode adicionar um botão com o nome bt_gravar_Alteracao e dentro do botão adicionar a mesma rotina do gravar, só que essa sem a pesquisa de última linha vazia, apenas alterando a linha ativa. Por exemplo;

‘BOTÃO DE ALTERAÇÃO
'Descarrega os dados do formulário na planilha.

x = txt_dt_rcbto_lote.Value
y = Format(x, "dd/mm/yyyy")
ActiveCell.Offset(0, -1).Value = y
ActiveCell.Offset(0, 0).Value = txt_num_lote.Value
ActiveCell.Offset(0, 1).Value = txt_referencia.Value
ActiveCell.Offset(0, 2).Value = txt_cliente.Value
ActiveCell.Offset(0, 3).Value = txt_pedido.Value
ActiveCell.Offset(0, 4).Value = txt_qtde_rcbto.Value
ActiveCell.Offset(0, 5).Value = txt_descricao.Value
ActiveCell.Offset(0, 6).Value = txt_valor.Value
ActiveCell.Offset(0, 7).Value = txt_fornecedor.Value
ActiveCell.Offset(0, 8).Value = txt_nf_rcbto.Value

i = txt_dt_dev_lote.Value
j = Format(i, "dd/mm/yyyy")
ActiveCell.Offset(0, 9).Value = j

ActiveCell.Offset(0, 10).Value = txt_nf_dev.Value
ActiveCell.Offset(0, 11).Value = txt_qtde_dev.Value
ActiveCell.Offset(0, 12).Value = txt_cont_fornec.Value
ActiveCell.Offset(0, 13).Value = txt_bonus.Value
ActiveCell.Offset(0, 14).Value = txt_valor_c_bonus.Value
ActiveCell.Offset(0, 15).Value = txt_valor_total_lote.Value

Atenciosamente

Tov Elen Shau

Reinaldo

21-09-2018 13:02:52

experimente: