Regina,
I looked at your book.
While I was able to save the code in another program, my machine is messed up and I could not save a copy of your book. I did correct many errors in the Form and in its code. Note that I first changed all the controls names to meaningful values. These Control name appear in the below code.
Option Explicit
Private Sub cbutAdicionarProfissional_Click()
'''''''validation'''''''
' Many of these "IsNumeric" checks are being applied to data that is Text, not numerical. Obviously, I did not correct these
If VBA.IsNumeric(Me.txbNIPC.Value) = False Then
MsgBox "Este campo só aceita valores numéricos.", vbCritical
Exit Sub
End If
If VBA.IsNumeric(Me.tbxCodigo.Value) = False Then
MsgBox "Este campo só aceita valores numéricos.", vbCritical
Exit Sub
End If
If VBA.IsNumeric(Me.txbValorServico.Value) = False Then
MsgBox "Este campo só aceita valores numéricos. Insira o Valor do Serviço.", vbCritical
Exit Sub
End If
If Me.tbxNome.Value = "" Then
MsgBox " Insira o nome do Profissional.", vbCritical
End If
If Me.txbMorada.Value = "" Then
MsgBox " Insira a Morada.", vbCritical
End If
If Me.txbEspecialidade.Value = "" Then
MsgBox " Insira a Especialidade.", vbCritical
End If
If Me.txbCedula.Value = "" Then
MsgBox " Insira a Cédula Profissional.", vbCritical
End If
If Me.txbDisponibilidade.Value = "" Then
MsgBox " Insira a Disponibilidade.", vbCritical
End If
If Me.txbObservacoes.Value = "" Then
MsgBox " Insira Obsservações", vbCritical
End If
If Me.tbxE_Mail.Value = "" Then
MsgBox " Insira o E-Mail.", vbCritical
End If
If Me.optEmpresa.Value = False And Me.optParticular.Value = False Then
MsgBox "Selecione o Tipo de Profissional: Particular ou Empresa.", vbCritical
End If
If Me.cmbZona.Value = "" Then
MsgBox "Selecione uma Zona.", vbCritical
End If
'''''''check the duplicate Código
Dim n As Long
With ThisWorkbook.Sheets("Base de Dados Profissionais")
If Application.CountIf(.Range("E:E"), Me.tbxCodigo.Value) = 0 Then
n = .Range("E" & .Rows.Count).End(xlUp).Row + 1
.Unprotect "1234"
.Range("E" & n).Value = tbxCodigo.Value
If optParticular.Value Then .Range("F" & n).Value = "Particular"
If optEmpresa.Value Then .Range("F" & n).Value = "Empresa"
.Range("G" & n).Resize(, 11).Value = Array(tbxNome.Value, txbNIPC.Value, txbMorada.Value, cmbZona.Value, txbEspecialidade.Value, txbCedula.Value, txbDisponibilidade.Value, txbValorServico.Value, tbxE_Mail.Value, txtTelefone.Value, txbObservacoes.Value)
.Protect "1234"
Else
MsgBox "Este Código já se encontra registado na Base de Dados de Profissionais.", vbCritical
End If
End With
End Sub
Private Sub cbutLimparProfissional_Click()
Me.tbxNome.Value = ""
Me.txbNIPC.Value = ""
Me.txbMorada.Value = ""
Me.txbEspecialidade.Value = ""
Me.txbCedula.Value = ""
Me.txbDisponibilidade.Value = ""
Me.txbValorServico.Value = ""
Me.txbObservacoes.Value = ""
Me.txtTelefone.Value = ""
Me.txbValorServico.Value = ""
Me.tbxCodigo.Value = ""
Me.cmbZona.Value = ""
Me.frmTipo.Controls.optParticular.Value = False
Me.frmTipo.Controls.optEmpresa.Value = False
End Sub
Private Sub UserForm_Activate()
With Me.cmbZona
.Clear
.AddItem ""
.AddItem "Norte"
.AddItem "Centro"
.AddItem "Sul"
.AddItem "Madeira"
.AddItem "Açores"
End With
End Sub