Erro no Aplicativo de Cadastro em VBA no Excel

israel17rj

04-07-2012 16:42:44

Prezados, boa tarde.

Peguei aqui mesmo no site um modelo pronto "Mudanças da Versão 3.5 – Tela de Pesquisa com ListView" (http://www.tomasvasquez.com.br/download ... stView.zip) eu estava fazendo uma alteração para adaptar na minha necessidade, porém está ocorrendo diversos erros ao trocar dos dados.
Ex.
Onde está por padrão na planílha;
Codigo da empresa eu queria colocar Controle
Nome da empresa queria colocar Analista
Nome do contato = incidente
Cargo = entrada
Cidade = Mês
Região = Alterado por
CEP = mes da alteração

Pelo que eu vi as informações sobre os tópicos (nome da empresa, codigo da empresa...) vem de uma outra planílha.
Eu realizo as alterações ,porem quando eu troco Cidade para Mes é apresentado erro.
Já não sei o que fazer, ja vi cada linha só que eu não consigo.

Se porventura se alguem poder me ajudar eu agradeço desde já! abraços

Rafael Monteiro

04-07-2012 17:19:36

Israel,

Para a conexão entre planilha e banco de dados funcionar corretamente você precisa alterar os titulos das colunas dentro do código VBA e também no Access.

Abs.

israel17rj

05-07-2012 09:15:55

Rafael bom dia.
Nesse sistema que o Thomás criou não utiliza Access, as colunas ficam na planilha do excel, eu realizei a alteração no VBA e na coluna do Excel, porém o erro so acontece se eu mudar a coluna Cidade.
Apresenta o erro "Erro em tempo de execução '-2147217904 (80040e10)"

Quando clico em depurar ele vai para a linha

Private Sub btnPesquisar_Click()
frmPesquisa.Show


End Sub
Na planílha está assim;
Controle Analista Incidente Entrada Status Mes

VBA
Option Explicit

Const colControle As Integer = 1
Const colAnalista As Integer = 2
Const colIncidente As Integer = 3
Const colEntrada As Integer = 4
Const colStatus As Integer = 5
Const colMes As Integer = 6
Const colAlteradoPor As Integer = 7
Const colMesDaAlteracao As Integer = 8
Const indiceMinimo As Byte = 2
Const corDisabledTextBox As Long = -2147483633
Const corEnabledTextBox As Long = -2147483643
Const nomePlanilhaCadastro As String = "Fornecedores"

Private wsCadastro As Worksheet
Private wbCadastro As Workbook
Private indiceRegistro As Long

Private Sub btnCancelar_Click()
btnOK.Enabled = False
btnCancelar.Enabled = False
Call DesabilitaControles
Call CarregaDadosInicial
Call HabilitaBotoesAlteracao
End Sub

Private Sub btnOK_Click()
Dim proximoId As Long

'Altera
If optAlterar.Value Then
Call SalvaRegistro(CLng(txtCodigoFornecedor.Text), indiceRegistro)
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Novo
If optNovo.Value Then
proximoId = PegaProximoId
'pega a próxima linha
Dim proximoIndice As Long
'atualiza o arquivo para pegar o próximo registro atualizado
Call AtualizarArquivo(False)
proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
Call SalvaRegistro(proximoId, proximoIndice)
txtCodigoFornecedor = proximoId
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Excluir
If optExcluir.Value Then
Dim result As VbMsgBoxResult
result = MsgBox("Deseja excluir o registro nº " & txtCodigoFornecedor.Text & " ?", vbYesNo, "Confirmação")

If result = vbYes Then
'abre o arquivo para escrita
Call AtualizarArquivo(False)
wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colControle), wsCadastro.Cells(indiceRegistro, colControle)).EntireRow.Delete
'salva
wbCadastro.Save
'abre somente leitura
Call AtualizarArquivo(True)
Call CarregaDadosInicial
lblMensagem.Caption = "Registro excluído com sucesso"
End If
End If

Call HabilitaBotoesAlteracao
Call DesabilitaControles

End Sub

Private Sub btnPesquisar_Click()
frmPesquisa.Show

End Sub




Private Sub optAlterar_Click()
If txtCodigoFornecedor.Text <> vbNullString And txtCodigoFornecedor.Text <> "" Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
txtNomeEmpresa.SetFocus
Else
lblMensagem.Caption = "Não há registro a ser alterado"
End If
End Sub

Private Sub optExcluir_Click()
If txtCodigoFornecedor.Text <> vbNullString And txtCodigoFornecedor.Text <> "" Then
Call DesabilitaBotoesAlteracao
lblMensagem.Caption = "Modo de exclusão. Confira o dados do registro antes de excluí-lo"
Else
lblMensagem.Caption = "Não há registro a ser excluído"
End If
End Sub

Private Sub optNovo_Click()
Call LimpaControles
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
txtNomeEmpresa.SetFocus
End Sub

Private Sub txtCidade_Change()

End Sub

Private Sub txtNomeEmpresa_Change()

End Sub

Private Sub UserForm_Initialize()

Call DefinePlanilhaDados
Call HabilitaBotoesAlteracao
Call CarregaDadosInicial
Call DesabilitaControles
End Sub

Private Sub btnAnterior_Click()
If indiceRegistro > indiceMinimo Then
indiceRegistro = indiceRegistro - 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnPrimeiro_Click()
indiceRegistro = indiceMinimo
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnProximo_Click()
If indiceRegistro < wsCadastro.UsedRange.Rows.Count Then
indiceRegistro = indiceRegistro + 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnUltimo_Click()
indiceRegistro = wsCadastro.UsedRange.Rows.Count
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub CarregaDadosInicial()
indiceRegistro = 2
Call CarregaRegistro
End Sub

Private Sub CarregaRegistro()
'carrega os dados do primeiro registro
With wsCadastro
If Not IsEmpty(.Cells(indiceRegistro, colControle)) Then
Me.txtCodigoFornecedor.Text = .Cells(indiceRegistro, colControle).Value
Me.txtNomeEmpresa.Text = .Cells(indiceRegistro, colAnalista).Value
Me.txtNomeContato.Text = .Cells(indiceRegistro, colIncidente).Value
Me.txtCargoContato.Text = .Cells(indiceRegistro, colEntrada).Value
Me.txtEndereco.Text = .Cells(indiceRegistro, colStatus).Value
Me.txtCidade.Text = .Cells(indiceRegistro, colMes).Value
Me.txtRegiao.Text = .Cells(indiceRegistro, colAlteradoPor).Value
Me.txtCEP.Text = .Cells(indiceRegistro, colMesDaAlteracao).Value

End If
End With

Call AtualizaRegistroCorrente
End Sub

Public Sub CarregaRegistroPorIndice(ByVal indice As Long)
'carrega os dados do registro baseado no índice
indiceRegistro = indice

Call CarregaRegistro
End Sub

Private Sub AtualizarArquivo(ByVal ReadOnly As Boolean)
Dim caminhoCompleto As String
'fecha o arquivo de dados e tenta abrí-lo
'guarda o caminho
caminhoCompleto = wbCadastro.FullName
wbCadastro.Saved = True
wbCadastro.Close SaveChanges:=False

'abre o arquivo em modo escrita
Set wbCadastro = Workbooks.Open(Filename:=caminhoCompleto, ReadOnly:=ReadOnly)

'oculta a janela
wbCadastro.Windows(1).Visible = False

'reatribui a planilha de cadastro
Set wsCadastro = wbCadastro.Worksheets(nomePlanilhaCadastro)
End Sub

Private Sub SalvaRegistro(ByVal id As Long, ByVal indice As Long)
'tenta abrir o arquivo em modo escrita
Call AtualizarArquivo(False)

With wsCadastro
.Cells(indice, colControle).Value = id
.Cells(indice, colAnalista).Value = Me.txtNomeEmpresa.Text
.Cells(indice, colIncidente).Value = Me.txtNomeContato.Text
.Cells(indice, colEntrada).Value = Me.txtCargoContato.Text
.Cells(indice, colStatus).Value = Me.txtEndereco.Text
.Cells(indice, colMes).Value = Me.txtCidade.Text
.Cells(indice, colAlteradoPor).Value = Me.txtRegiao.Text
.Cells(indice, colMesDaAlteracao).Value = Me.txtCEP.Text

End With

'salva o arquivo
Call wbCadastro.Save

'abre o arquivo novamente em modo leitura
Call AtualizarArquivo(True)

Call AtualizaRegistroCorrente
End Sub

Private Function PegaProximoId() As Long
Dim rangeIds As Range
'pega o range que se refere a toda a coluna do código (id)
Set rangeIds = wsCadastro.Range(wsCadastro.Cells(indiceMinimo, colControle), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colControle))
PegaProximoId = WorksheetFunction.Max(rangeIds) + 1
End Function

Private Sub AtualizaRegistroCorrente()
lblNavigator.Caption = indiceRegistro - 1 & " de " & wsCadastro.UsedRange.Rows.Count - 1
lblMensagem.Caption = ""
End Sub

Private Sub LimpaControles()
Me.txtCodigoFornecedor.Text = ""
Me.txtNomeEmpresa.Text = ""
Me.txtNomeContato.Text = ""
Me.txtCargoContato.Text = ""
Me.txtEndereco.Text = ""
Me.txtCidade.Text = ""
Me.txtRegiao.Text = ""
Me.txtCEP.Text = ""

End Sub

Private Sub HabilitaControles()
'Me.txtCodigoFornecedor.Locked = False
Me.txtNomeEmpresa.Locked = False
Me.txtNomeContato.Locked = False
Me.txtCargoContato.Locked = False
Me.txtEndereco.Locked = False
Me.txtCidade.Locked = False
Me.txtRegiao.Locked = False
Me.txtCEP.Locked = False


Me.txtNomeEmpresa.BackColor = corEnabledTextBox
Me.txtNomeContato.BackColor = corEnabledTextBox
Me.txtCargoContato.BackColor = corEnabledTextBox
Me.txtEndereco.BackColor = corEnabledTextBox
Me.txtCidade.BackColor = corEnabledTextBox
Me.txtRegiao.BackColor = corEnabledTextBox
Me.txtCEP.BackColor = corEnabledTextBox

End Sub

Private Sub DesabilitaControles()
'Me.txtCodigoFornecedor.Locked = True
Me.txtNomeEmpresa.Locked = True
Me.txtNomeContato.Locked = True
Me.txtCargoContato.Locked = True
Me.txtEndereco.Locked = True
Me.txtCidade.Locked = True
Me.txtRegiao.Locked = True
Me.txtCEP.Locked = True


Me.txtNomeEmpresa.BackColor = corDisabledTextBox
Me.txtNomeContato.BackColor = corDisabledTextBox
Me.txtCargoContato.BackColor = corDisabledTextBox
Me.txtEndereco.BackColor = corDisabledTextBox
Me.txtCidade.BackColor = corDisabledTextBox
Me.txtRegiao.BackColor = corDisabledTextBox
Me.txtCEP.BackColor = corDisabledTextBox

End Sub

Private Sub HabilitaBotoesAlteracao()
'habilita os botões de alteração
optAlterar.Enabled = True
optExcluir.Enabled = True
optNovo.Enabled = True
btnPesquisar.Enabled = True
btnOK.Enabled = False
btnCancelar.Enabled = False

'limpa os valores dos controles
optAlterar.Value = False
optExcluir.Value = False
optNovo.Value = False
End Sub

Private Sub DesabilitaBotoesAlteracao()
'desabilita os botões de alteração
optAlterar.Enabled = False
optExcluir.Enabled = False
optNovo.Enabled = False
btnPesquisar.Enabled = False
btnOK.Enabled = True
btnCancelar.Enabled = True
End Sub

Public Function ProcuraIndiceRegistroPodId(ByVal id As Long) As Long
Dim i As Long
Dim retorno As Long
Dim encontrado As Boolean

i = indiceMinimo
With wsCadastro
Do While Not IsEmpty(.Cells(i, colControle))
If .Cells(i, colControle).Value = id Then
retorno = i
encontrado = True
Exit Do
End If
i = i + 1
Loop
End With

'caso não encontre o registro, retorna -1
If Not encontrado Then
retorno = -1
End If

ProcuraIndiceRegistroPodId = i
End Function

Private Sub DefinePlanilhaDados()
Dim abrirArquivo As Boolean
Dim wb As Workbook
Dim caminhoCompleto As String
Dim ARQUIVO_DADOS As String
Dim PASTA_DADOS As String

abrirArquivo = True

ARQUIVO_DADOS = Range("ARQUIVO_DADOS").Value
PASTA_DADOS = Range("PASTA_DADOS").Value

If ThisWorkbook.Name <> ARQUIVO_DADOS Then
'monta a string do caminho completo
If PASTA_DADOS = vbNullString Or PASTA_DADOS = "" Then
caminhoCompleto = Replace(ThisWorkbook.FullName, ThisWorkbook.Name, vbNullString) & ARQUIVO_DADOS
Else
If Right(PASTA_DADOS, 1) = "\" Then
caminhoCompleto = PASTA_DADOS & ARQUIVO_DADOS
Else
caminhoCompleto = PASTA_DADOS & "\" & ARQUIVO_DADOS
End If
End If

'verifica se o arquivo não está aberto
For Each wb In Application.Workbooks
If wb.Name = ARQUIVO_DADOS Then
abrirArquivo = False
Exit For
End If
Next

'atribui o arquivo
If abrirArquivo Then
Set wbCadastro = Workbooks.Open(Filename:=caminhoCompleto, ReadOnly:=True)
Else
Set wbCadastro = Workbooks(ARQUIVO_DADOS)
End If
Else
Set wbCadastro = ThisWorkbook
End If

Set wsCadastro = wbCadastro.Worksheets(nomePlanilhaCadastro)

'oculta o arquivo de dados
wbCadastro.Windows(1).Visible = False

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'fecha a planilha de dados, se estiver aberta
If Not wbCadastro Is Nothing Then
wbCadastro.Saved = True
wbCadastro.Close SaveChanges:=False
End If

Set wbCadastro = Nothing
End Sub

israel17rj

05-07-2012 11:33:39

Vendo aqui eu peguei a planilha do zero e só alterei de Cidade para Cidades ai alterei no vba para cidades também ai acontece o mesmo erro. Testem ai vcs para ve se não acontece tb. abraço

Rafael Monteiro

05-07-2012 12:28:34

Bom dia Israel,

Você não deve mudar a coluna ID, ela é essencial para o funcionamento do listview. Comece alterar a partir da 2° coluna. Altere o BD e as strings ref. à coluna que desejar modificar.

Alterei 2 colunas da planilha, inclusive a coluna 'cidade' para que você possa ver o exemplo. Siga a mesma lógica.

Deve também ficar atento às colunas que podem ser pesquisadas, nelas também são necessário alterar as strings.

Abs.

israel17rj

06-07-2012 10:53:41

Rafael muito obrigado pela sua ajuda, pelo o seu ajuste eu pudi ver onde eu estava errando, agora está tudo funcionando corretamente. Abraços

Rafael Monteiro

06-07-2012 12:15:02

valeu!! ;)

emersonmizael

30-08-2012 00:25:53

Prezados,

Peguei aqui no site o modelo de cadastro e adaptei as minhas necesidades, porém ao carregar ele dá erro. Não consigo arrumar, se alguem puder dar uma ajuda, deve existir mais erros, mas se conseguir fazer carregar consigo alterar o resto. Segue o código na integra:

Option Explicit

Const colCódigoDoFornecedor As Integer = 1
Const colDATA_DE_INSCRIÇÃO As Integer = 2
Const colANO_EXERCÍCIO As Integer = 3
Const colSITUACAO_MATRICULA As Integer = 4
Const colRA As Integer = 5
Const colNOME_ALUNO As Integer = 6
Const colDATA_DE_NASCIMENTO As Integer = 7
Const colCURSO As Integer = 8
Const colSERIE As Integer = 9
Const colTURNO As Integer = 10
Const colTURMA As Integer = 11
Const colESCOLA_DE_ORIGEM As Integer = 12
Const colUF As Integer = 13
Const colEX_ALUNO As Integer = 14
Const colULTIMO_ANO As Integer = 15
Const colINTERCAMBIO As Integer = 16
Const colSOCIALIZAÇÃO As Integer = 17
Const colDATA_DA_SOCIALIZAÇÃO As Integer = 18
Const colLOCAL_DE_INSCRIÇÃO As Integer = 19
Const colPAGAMENTO As Integer = 20
Const colDECLARAÇÃO_DE_FREQUENCIA As Integer = 21
Const colBOLETIM As Integer = 22
Const colCERTIDÃO_DE_NASCIMENTO As Integer = 23
Const colFOTO_3X4 As Integer = 24
Const colRG_CPF_PAI As Integer = 25
Const colRG_CPF_MÃE As Integer = 26
Const colRG_CPF_RESP_FINANCEIRO As Integer = 27
Const colCARTEIRA_DE_VACINAÇÃO As Integer = 28
Const colDECLARAÇÃO_DE_TRANSFERÊNCIA As Integer = 29
Const colDECLARAÇÃO_DE_QUITAÇÃO As Integer = 30
Const colHISTÓRICO_EF As Integer = 31
Const colHISTORICO_EM As Integer = 32
Const colFICHA_INDIVIDUAL As Integer = 33
Const colCOMPROVANTE_DE_RESIDENCIA As Integer = 34
Const indiceMinimo As Byte = 2
Const corDisabledTextBox As Long = -2147483633
Const corEnabledTextBox As Long = -2147483643

Private wsCadastro As Worksheet
Private indiceRegistro As Long

Private Sub btnCancelar_Click()
btnOK.Enabled = False
btnCancelar.Enabled = False
Call DesabilitaControles
Call CarregaDadosInicial
Call HabilitaBotoesAlteracao
End Sub

Private Sub btnOK_Click()
Dim proximoId As Long

'Altera
If optAlterar.Value Then
Call SalvaRegistro(CLng(txtCodigoFornecedor.Text), indiceRegistro)
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Novo
If optNovo.Value Then
proximoId = PegaProximoId
'pega a próxima linha
Dim proximoIndice As Long
proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
Call SalvaRegistro(proximoId, proximoIndice)
txtCodigoFornecedor = proximoId
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Excluir
If optExcluir.Value Then
Dim result As VbMsgBoxResult
result = MsgBox("Deseja excluir o registro nº " & txtCodigoFornecedor.Text & " ?", vbYesNo, "Confirmação")

If result = vbYes Then
wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colCodigoDoFornecedor), wsCadastro.Cells(indiceRegistro, colCodigoDoFornecedor)).EntireRow.Delete
Call CarregaDadosInicial
lblMensagem.Caption = "Registro excluído com sucesso"
End If
End If

Call HabilitaBotoesAlteracao
Call DesabilitaControles

End Sub


Private Sub optAlterar_Click()
If txtCodigoFornecedor.Text <> vbNullString And txtCodigoFornecedor.Text <> "" Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
cboPeriodoLetivo.SetFocus
Else
lblMensagem.Caption = "Não há registro a ser alterado"
End If
End Sub

Private Sub optExcluir_Click()
If txtCodigoFornecedor.Text <> vbNullString And txtCodigoFornecedor.Text <> "" Then
Call DesabilitaBotoesAlteracao
lblMensagem.Caption = "Modo de exclusão. Confira o dados do registro antes de excluí-lo"
Else
lblMensagem.Caption = "Não há registro a ser excluído"
End If
End Sub

Private Sub optNovo_Click()
Call LimpaControles
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
cboPeriodoLetivo.SetFocus
End Sub

Private Sub UserForm_Initialize()
Set wsCadastro = ThisWorkbook.Worksheets("NOVATOS")
Call HabilitaBotoesAlteracao
Call CarregaDadosInicial
Call DesabilitaControles
End Sub

Private Sub btnAnterior_Click()
If indiceRegistro > indiceMinimo Then
indiceRegistro = indiceRegistro - 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnPrimeiro_Click()
indiceRegistro = indiceMinimo
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnProximo_Click()
If indiceRegistro < wsCadastro.UsedRange.Rows.Count Then
indiceRegistro = indiceRegistro + 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub btnUltimo_Click()
indiceRegistro = wsCadastro.UsedRange.Rows.Count
If indiceRegistro > 1 Then
Call CarregaRegistro
End If
End Sub

Private Sub CarregaDadosInicial()
indiceRegistro = 2
Call CarregaRegistro
End Sub

Private Sub CarregaRegistro()
'carrega os dados do primeiro registro
With wsCadastro
If Not IsEmpty(.Cells(indiceRegistro, colNOME_ALUNO)) Then
Me.txtCodigoFornecedor.Text = .Cells(indiceRegistro, colCodigoDoFornecedor).Value
Me.cboPeriodoLetivo.Value = .Cells(indiceRegistro, colDATA_DE_INSCRIÇÃO).Value
Me.txtData.Value = .Cells(indiceRegistro, colANO_EXERCÍCIO).Value
Me.txtRA.Value = .Cells(indiceRegistro, colSITUACAO_MATRICULA).Value
Me.txtAluno.Value = .Cells(indiceRegistro, colRA).Value
Me.txtNascimento.Value = .Cells(indiceRegistro, colNOME_ALUNO).Value
Me.cboCurso.Value = .Cells(indiceRegistro, colDATA_DE_NASCIMENTO).Value
Me.cboSerie.Value = .Cells(indiceRegistro, colCURSO).Value
Me.cboTurno.Value = .Cells(indiceRegistro, colSERIE).Value
Me.txtTurma.Value = .Cells(indiceRegistro, colTURNO).Value
Me.txtEscola.Value = .Cells(indiceRegistro, colTURMA).Value
Me.cboUF.Value = .Cells(indiceRegistro, colESCOLA_DE_ORIGEM).Value
Me.cboExaluno.Value = .Cells(indiceRegistro, colUF).Value
Me.txtUltimo.Value = .Cells(indiceRegistro, colEX_ALUNO).Value
Me.cbointerc.Value = .Cells(indiceRegistro, colULTIMO_ANO).Value
Me.cbosocializ.Value = .Cells(indiceRegistro, colINTERCAMBIO).Value
Me.txtDTsocializa.Value = .Cells(indiceRegistro, colSOCIALIZAÇÃO).Value
Me.cboForma.Value = .Cells(indiceRegistro, colDATA_DA_SOCIALIZAÇÃO).Value
Me.cboPG.Value = .Cells(indiceRegistro, colLOCAL_DE_INSCRIÇÃO).Value
Me.cboStatus.Value = .Cells(indiceRegistro, colPAGAMENTO).Value
Me.chkdecf.Value = .Cells(indiceRegistro, colDECLARAÇÃO_DE_FREQUENCIA).Value
Me.chkbol.Value = .Cells(indiceRegistro, colBOLETIM).Value
Me.chkcertnasc.Value = .Cells(indiceRegistro, colCERTIDÃO_DE_NASCIMENTO).Value
Me.chkfoto.Value = .Cells(indiceRegistro, colFOTO_3X4).Value
Me.chkpai.Value = .Cells(indiceRegistro, colRG_CPF_PAI).Value
Me.chkmae.Value = .Cells(indiceRegistro, colRG_CPF_MÃE).Value
Me.chkfinanc.Value = .Cells(indiceRegistro, colRG_CPF_RESP_FINANCEIRO).Value
Me.chkvacin.Value = .Cells(indiceRegistro, colCARTEIRA_DE_VACINAÇÃO).Value
Me.chkdectransf.Value = .Cells(indiceRegistro, colDECLARAÇÃO_DE_TRANSFERÊNCIA).Value
Me.chkquit.Value = .Cells(indiceRegistro, colDECLARAÇÃO_DE_QUITAÇÃO).Value
Me.chkhistf.Value = .Cells(indiceRegistro, colHISTÓRICO_EF).Value
Me.chkhistm.Value = .Cells(indiceRegistro, colHISTORICO_EM).Value
Me.chkfi.Value = .Cells(indiceRegistro, colFICHA_INDIVIDUAL).Value
Me.chkres.Value = .Cells(indiceRegistro, colCOMPROVANTE_DE_RESIDENCIA).Value

End If
End With

Call AtualizaRegistroCorrente
End Sub

Public Sub CarregaRegistroPorIndice(ByVal indice As Long)
'carrega os dados do registro baseado no índice
indiceRegistro = indice

Call CarregaRegistro
End Sub

Private Sub SalvaRegistro(ByVal id As Long, ByVal indice As Long)
With wsCadastro
.Cells(indice, colCodigoDoFornecedor).Value = id
.Cells(indice, colDATA_DE_INSCRIÇÃO).Value = Me.cboPeriodoLetivo.Value
.Cells(indice, colANO_EXERCÍCIO).Value = Me.txtData.Value
.Cells(indice, colSITUACAO_MATRICULA).Value = Me.txtRA.Value
.Cells(indice, colRA).Value = Me.txtAluno.Value
.Cells(indice, colNOME_ALUNO).Value = Me.txtNascimento.Value
.Cells(indice, colDATA_DE_NASCIMENTO).Value = Me.cboCurso.Value
.Cells(indice, colCURSO).Value = Me.cboSerie.Value
.Cells(indice, colSERIE).Value = Me.cboTurno.Value
.Cells(indice, colTURNO).Value = Me.txtTurma.Value
.Cells(indice, colTURMA).Value = Me.txtEscola.Value
.Cells(indice, colESCOLA_DE_ORIGEM).Value = Me.cboUF.Value
.Cells(indice, colUF).Value = Me.cboExaluno.Value
.Cells(indice, colEX_ALUNO).Value = Me.txtUltimo.Value
.Cells(indice, colULTIMO_ANO).Value = Me.cbointerc.Value
.Cells(indice, colINTERCAMBIO).Value = Me.cbosocializ.Value
.Cells(indice, colSOCIALIZAÇÃO).Value = Me.txtDTsocializa.Value
.Cells(indice, colDATA_DA_SOCIALIZAÇÃO).Value = Me.cboForma.Value
.Cells(indice, colLOCAL_DE_INSCRIÇÃO).Value = Me.cboPG.Value
.Cells(indice, colPAGAMENTO).Value = Me.cboStatus.Value
.Cells(indice, colDECLARAÇÃO_DE_FREQUENCIA).Value = Me.chkdecf.Value
.Cells(indice, colBOLETIM).Value = Me.chkbol.Value
.Cells(indice, colCERTIDÃO_DE_NASCIMENTO).Value = Me.chkcertnasc.Value
.Cells(indice, colFOTO_3X4).Value = Me.chkfoto.Value
.Cells(indice, colRG_CPF_PAI).Value = Me.chkpai.Value
.Cells(indice, colRG_CPF_MÃE).Value = Me.chkmae.Value
.Cells(indice, colRG_CPF_RESP_FINANCEIRO).Value = Me.chkfinanc.Value
.Cells(indice, colCARTEIRA_DE_VACINAÇÃO).Value = Me.chkvacin.Value
.Cells(indice, colDECLARAÇÃO_DE_TRANSFERÊNCIA).Value = Me.chkdectransf.Value
.Cells(indice, colDECLARAÇÃO_DE_QUITAÇÃO).Value = Me.chkquit.Value
.Cells(indice, colHISTÓRICO_EF).Value = Me.chkhistf.Value
.Cells(indice, colHISTORICO_EM).Value = Me.chkhistm.Value
.Cells(indice, colFICHA_INDIVIDUAL).Value = Me.chkfi.Value
.Cells(indice, colCOMPROVANTE_DE_RESIDENCIA).Value = Me.chkres.Value
End With

Call AtualizaRegistroCorrente
End Sub

Private Function PegaProximoId() As Long
Dim rangeIds As Range
'pega o range que se refere a toda a coluna do código (id)
Set rangeIds = wsCadastro.Range(wsCadastro.Cells(indiceMinimo, colCodigoDoFornecedor), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colCodigoDoFornecedor))
PegaProximoId = WorksheetFunction.Max(rangeIds) + 1
End Function

Private Sub AtualizaRegistroCorrente()
lblNavigator.Caption = indiceRegistro - 1 & " de " & wsCadastro.UsedRange.Rows.Count - 1
lblMensagem.Caption = ""
End Sub

Private Sub LimpaControles()
Me.txtCodigoFornecedor.Text = ""
Me.cboPeriodoLetivo.Value = ""
Me.txtData.Value = ""
Me.txtRA.Value = ""
Me.txtAluno.Value = ""
Me.txtNascimento.Value = ""
Me.cboCurso.Value = ""
Me.cboSerie.Value = ""
Me.cboTurno.Value = ""
Me.txtTurma.Value = ""
Me.txtEscola.Value = ""
Me.cboUF.Value = ""
Me.cboExaluno.Value = ""
Me.txtUltimo.Value = ""
Me.cbointerc.Value = ""
Me.cbosocializ.Value = ""
Me.txtDTsocializa.Value = ""
Me.cboForma.Value = ""
Me.cboPG.Value = ""
Me.cboStatus.Value = ""
Me.chkdecf.Value = False
Me.chkbol.Value = False
Me.chkcertnasc.Value = False
Me.chkfoto.Value = False
Me.chkpai.Value = False
Me.chkmae.Value = False
Me.chkfinanc.Value = False
Me.chkvacin.Value = False
Me.chkdectransf.Value = False
Me.chkquit.Value = False
Me.chkhistf.Value = False
Me.chkhistm.Value = False
Me.chkfi.Value = False
Me.chkres.Value = False

End Sub

Private Sub HabilitaControles()
'Me.txtCodigoFornecedor.Locked = False
Me.cboPeriodoLetivo.Locked = False
Me.txtData.Locked = False
Me.txtRA.Locked = False
Me.txtAluno.Locked = False
Me.txtNascimento.Locked = False
Me.cboCurso.Locked = False
Me.cboSerie.Locked = False
Me.cboTurno.Locked = False
Me.txtTurma.Locked = False
Me.txtEscola.Locked = False
Me.cboUF.Locked = False
Me.cboExaluno.Locked = False
Me.txtUltimo.Locked = False
Me.cbointerc.Locked = False
Me.cbosocializ.Locked = False
Me.txtDTsocializa.Locked = False
Me.cboForma.Locked = False
Me.cboPG.Locked = False
Me.cboStatus.Locked = False
Me.chkdecf.Locked = False
Me.chkbol.Locked = False
Me.chkcertnasc.Locked = False
Me.chkfoto.Locked = False
Me.chkpai.Locked = False
Me.chkmae.Locked = False
Me.chkfinanc.Locked = False
Me.chkvacin.Locked = False
Me.chkdectransf.Locked = False
Me.chkquit.Locked = False
Me.chkhistf.Locked = False
Me.chkhistm.Locked = False
Me.chkfi.Locked = False
Me.chkres.Locked = False


Me.cboPeriodoLetivo.BackColor = corEnabledTextBox
Me.txtData.BackColor = corEnabledTextBox
Me.txtRA.BackColor = corEnabledTextBox
Me.txtAluno.BackColor = corEnabledTextBox
Me.txtNascimento.BackColor = corEnabledTextBox
Me.cboCurso.BackColor = corEnabledTextBox
Me.cboSerie.BackColor = corEnabledTextBox
Me.cboTurno.BackColor = corEnabledTextBox
Me.txtTurma.BackColor = corEnabledTextBox
Me.txtEscola.BackColor = corEnabledTextBox
Me.cboUF.BackColor = corEnabledTextBox
Me.cboExaluno.BackColor = corEnabledTextBox
Me.txtUltimo.BackColor = corEnabledTextBox
Me.cbointerc.BackColor = corEnabledTextBox
Me.cbosocializ.BackColor = corEnabledTextBox
Me.txtDTsocializa.BackColor = corEnabledTextBox
Me.cboForma.BackColor = corEnabledTextBox
Me.cboPG.BackColor = corEnabledTextBox
Me.cboStatus.BackColor = corEnabledTextBox
Me.chkdecf.BackColor = corEnabledTextBox
Me.chkbol.BackColor = corEnabledTextBox
Me.chkcertnasc.BackColor = corEnabledTextBox
Me.chkfoto.BackColor = corEnabledTextBox
Me.chkpai.BackColor = corEnabledTextBox
Me.chkmae.BackColor = corEnabledTextBox
Me.chkfinanc.BackColor = corEnabledTextBox
Me.chkvacin.BackColor = corEnabledTextBox
Me.chkdectransf.BackColor = corEnabledTextBox
Me.chkquit.BackColor = corEnabledTextBox
Me.chkhistf.BackColor = corEnabledTextBox
Me.chkhistm.BackColor = corEnabledTextBox
Me.chkfi.BackColor = corEnabledTextBox
Me.chkres.BackColor = corEnabledTextBox

End Sub

Private Sub DesabilitaControles()
'Me.txtCodigoFornecedor.Locked = True
Me.cboPeriodoLetivo.Locked = True
Me.txtData.Locked = True
Me.txtRA.Locked = True
Me.txtAluno.Locked = True
Me.txtNascimento.Locked = True
Me.cboCurso.Locked = True
Me.cboSerie.Locked = True
Me.cboTurno.Locked = True
Me.txtTurma.Locked = True
Me.txtEscola.Locked = True
Me.cboUF.Locked = True
Me.cboExaluno.Locked = True
Me.txtUltimo.Locked = True
Me.cbointerc.Locked = True
Me.cbosocializ.Locked = True
Me.txtDTsocializa.Locked = True
Me.cboForma.Locked = True
Me.cboPG.Locked = True
Me.cboStatus.Locked = True
Me.chkdecf.Locked = True
Me.chkbol.Locked = True
Me.chkcertnasc.Locked = True
Me.chkfoto.Locked = True
Me.chkpai.Locked = True
Me.chkmae.Locked = True
Me.chkfinanc.Locked = True
Me.chkvacin.Locked = True
Me.chkdectransf.Locked = True
Me.chkquit.Locked = True
Me.chkhistf.Locked = True
Me.chkhistm.Locked = True
Me.chkfi.Locked = True
Me.chkres.Locked = True


Me.cboPeriodoLetivo.BackColor = corDisabledTextBox
Me.txtData.BackColor = corDisabledTextBox
Me.txtRA.BackColor = corDisabledTextBox
Me.txtAluno.BackColor = corDisabledTextBox
Me.txtNascimento.BackColor = corDisabledTextBox
Me.cboCurso.BackColor = corDisabledTextBox
Me.cboSerie.BackColor = corDisabledTextBox
Me.cboTurno.BackColor = corDisabledTextBox
Me.txtTurma.BackColor = corDisabledTextBox
Me.txtEscola.BackColor = corDisabledTextBox
Me.cboUF.BackColor = corDisabledTextBox
Me.cboExaluno.BackColor = corDisabledTextBox
Me.txtUltimo.BackColor = corDisabledTextBox
Me.cbointerc.BackColor = corDisabledTextBox
Me.cbosocializ.BackColor = corDisabledTextBox
Me.txtDTsocializa.BackColor = corDisabledTextBox
Me.cboForma.BackColor = corDisabledTextBox
Me.cboPG.BackColor = corDisabledTextBox
Me.cboStatus.BackColor = corDisabledTextBox
Me.chkdecf.BackColor = corDisabledTextBox
Me.chkbol.BackColor = corDisabledTextBox
Me.chkcertnasc.BackColor = corDisabledTextBox
Me.chkfoto.BackColor = corDisabledTextBox
Me.chkpai.BackColor = corDisabledTextBox
Me.chkmae.BackColor = corDisabledTextBox
Me.chkfinanc.BackColor = corDisabledTextBox
Me.chkvacin.BackColor = corDisabledTextBox
Me.chkdectransf.BackColor = corDisabledTextBox
Me.chkquit.BackColor = corDisabledTextBox
Me.chkhistf.BackColor = corDisabledTextBox
Me.chkhistm.BackColor = corDisabledTextBox
Me.chkfi.BackColor = corDisabledTextBox
Me.chkres.BackColor = corDisabledTextBox

End Sub

Private Sub HabilitaBotoesAlteracao()
'habilita os botões de alteração
optAlterar.Enabled = True
optExcluir.Enabled = True
optNovo.Enabled = True
btnOK.Enabled = False
btnCancelar.Enabled = False

'limpa os valores dos controles
optAlterar.Value = False
optExcluir.Value = False
optNovo.Value = False
End Sub

Private Sub DesabilitaBotoesAlteracao()
'desabilita os botões de alteração
optAlterar.Enabled = False
optExcluir.Enabled = False
optNovo.Enabled = False
btnOK.Enabled = True
btnCancelar.Enabled = True
End Sub

Public Function ProcuraIndiceRegistroPodId(ByVal id As Long) As Long
Dim i As Long
Dim retorno As Long
Dim encontrado As Boolean

i = indiceMinimo
With wsCadastro
Do While Not IsEmpty(.Cells(i, colCodigoDoFornecedor))
If .Cells(i, colCodigoDoFornecedor).Value = id Then
retorno = i
encontrado = True
Exit Do
End If
i = i + 1
Loop
End With

'caso não encontre o registro, retorna -1
If Not encontrado Then
retorno = -1
End If

ProcuraIndiceRegistroPodId = i
End Function

Agradeço quem puder ajudar.

Rafael Monteiro

30-08-2012 12:08:51

Emerson,

Segue em anexo a solução.

O erro estava nessa linha:

Código: Selecionar todos

colCódigoDoFornecedor)

emersonmizael

30-08-2012 19:10:08

Rafael escreveu:Emerson,

Segue em anexo a solução.

O erro estava nessa linha:

Código: Selecionar todos

colCódigoDoFornecedor)
Rafael, muito obrigado pela dica. Era isso mesmo, deu certo agora. Se eu tiver problemas eu procuro novamente. vlw

Rafael Monteiro

30-08-2012 19:19:42

Estando ao alcance! ;)

AlineMartins

22-05-2013 14:09:03

Bom dia,

Adaptei o cadastro de acordo com minhas necessidades, e ele abre normalmente. No entanto, há 2 coisas que preciso que ele execute e já estudei os códigos e não consegui detectar onde está o problema:
1 - Ele não está salvando os cadastros feitos por mim
2 - Ao cadastrar um novo contato, ele mantém o nome do cliente mas ele carrega os dados cadastrais (endereço, cep, telefone, etc) do contato anterior. Ao sair e retornar ao programa, constatei que as informações não estão sendo salvas.

Segue abaixo o código. Alguém pode me ajudar?

Option Explicit

Const colCodigoDoCliente As Integer = 1
Const colCliente As Integer = 5
Const colEndereco As Integer = 6
Const colNumero As Integer = 7
Const colBairro As Integer = 8
Const colCidade As Integer = 9
Const colUF As Integer = 10
Const colCep As Integer = 11
Const colPais As Integer = 12
Const colDDD1 As Integer = 13
Const colTelefone1 As Integer = 14
Const colDDD2 As Integer = 15
Const colTelefone2 As Integer = 16
Const colSite As Integer = 17
Const colModalidadeDoCliente As Integer = 18
Const colCoordenador As Integer = 19
Const colRamalCoordenador As Integer = 20
Const colEmailCoordenador As Integer = 21
Const colCelularCoordenador As Integer = 22
Const colProjetista As Integer = 23
Const colRamalProjetista As Integer = 24
Const colEmailProjetista As Integer = 25
Const colCelularProjetista As Integer = 26
Const colVendedor As Integer = 27
Const colRamalVendedor As Integer = 28
Const colEmailVendedor As Integer = 29
Const colCelularVendedor As Integer = 30
Const colGestor As Integer = 31
Const colRamalGestor As Integer = 32
Const colEmailGestor As Integer = 33
Const colCelularGestor As Integer = 34
Const colContato1 As Integer = 35
Const colTelefoneContato1 As Integer = 36
Const colCelularContato1 As Integer = 37
Const colCargoContato1 As Integer = 38
Const colEmailContato1 As Integer = 39
Const colContato2 As Integer = 40
Const colTelefoneContato2 As Integer = 41
Const colCelularContato2 As Integer = 42
Const colCargoContato2 As Integer = 43
Const colEmailContato2 As Integer = 44
Const colContato3 As Integer = 45
Const colTelefoneContato3 As Integer = 46
Const colCelularContato3 As Integer = 47
Const colCargoContato3 As Integer = 48
Const colEmailContato3 As Integer = 49
Const colContato4 As Integer = 50
Const colTelefoneContato4 As Integer = 51
Const colCelularContato4 As Integer = 52
Const colCargoContato4 As Integer = 53
Const colEmailContato4 As Integer = 54
Const colContato5 As Integer = 55
Const colTelefoneContato5 As Integer = 56
Const colCelularContato5 As Integer = 57
Const colCargoContato5 As Integer = 58
Const colEmailContato5 As Integer = 59
Const colContato6 As Integer = 60
Const colTelefoneContato6 As Integer = 61
Const colCelularContato6 As Integer = 62
Const colCargoContato6 As Integer = 63
Const colEmailContato6 As Integer = 64
Const colContato7 As Integer = 65
Const colTelefoneContato7 As Integer = 66
Const colCelularContato7 As Integer = 67
Const colCargoContato7 As Integer = 68
Const colEmailContato7 As Integer = 69
Const ColContato8 As Integer = 70
Const ColTelefoneContato8 As Integer = 71
Const ColCelularContato8 As Integer = 72
Const ColCargoContato8 As Integer = 73
Const ColEmailContato8 As Integer = 74
Const ColContato9 As Integer = 75
Const ColTelefoneContato9 As Integer = 76
Const ColCelularContato9 As Integer = 77
Const ColCargoContato9 As Integer = 78
Const ColEmailContato9 As Integer = 79
Const ColContato10 As Integer = 80
Const ColTelefoneContato10 As Integer = 81
Const ColCelularContato10 As Integer = 82
Const ColCargoContato10 As Integer = 83
Const ColEmailContato10 As Integer = 84
Const ColContato11 As Integer = 85
Const ColTelefoneContato11 As Integer = 86
Const ColCelularContato11 As Integer = 87
Const ColCargoContato11 As Integer = 88
Const ColEmailContato11 As Integer = 89
Const ColContato12 As Integer = 90
Const ColTelefoneContato12 As Integer = 91
Const ColCelularContato12 As Integer = 92
Const ColCargoContato12 As Integer = 93
Const ColEmailContato12 As Integer = 94
Const ColContato13 As Integer = 95
Const ColTelefoneContato13 As Integer = 96
Const ColCelularContato13 As Integer = 97
Const ColCargoContato13 As Integer = 98
Const ColEmailContato13 As Integer = 99
Const ColContato14 As Integer = 100
Const ColTelefoneContato14 As Integer = 101
Const ColCelularContato14 As Integer = 102
Const ColCargoContato14 As Integer = 103
Const ColEmailContato14 As Integer = 104
Const ColContato15 As Integer = 105
Const ColTelefoneContato15 As Integer = 106
Const ColCelularContato15 As Integer = 107
Const ColCargoContato15 As Integer = 108
Const ColEmailContato15 As Integer = 109
Const ColContato16 As Integer = 110
Const ColTelefoneContato16 As Integer = 111
Const ColCelularContato16 As Integer = 112
Const ColCargoContato16 As Integer = 113
Const ColEmailContato16 As Integer = 114
Const ColContato17 As Integer = 115
Const ColTelefoneContato17 As Integer = 116
Const ColCelularContato17 As Integer = 117
Const ColCargoContato17 As Integer = 118
Const ColEmailContato17 As Integer = 119
Const ColContato18 As Integer = 120
Const ColTelefoneContato18 As Integer = 121
Const ColCelularContato18 As Integer = 122
Const ColCargoContato18 As Integer = 123
Const ColEmailContato18 As Integer = 124
Const ColContato19 As Integer = 125
Const ColTelefoneContato19 As Integer = 126
Const ColCelularContato19 As Integer = 127
Const ColCargoContato19 As Integer = 128
Const ColEmailContato19 As Integer = 129
Const ColContato20 As Integer = 130
Const ColTelefoneContato20 As Integer = 131
Const ColCelularContato20 As Integer = 132
Const ColCargoContato20 As Integer = 133
Const ColEmailContato20 As Integer = 134
Const ColContato21 As Integer = 135
Const ColTelefoneContato21 As Integer = 136
Const ColCelularContato21 As Integer = 137
Const ColCargoContato21 As Integer = 138
Const ColEmailContato21 As Integer = 139
Const ColContato22 As Integer = 140
Const ColTelefoneContato22 As Integer = 141
Const ColCelularContato22 As Integer = 142
Const ColCargoContato22 As Integer = 143
Const ColEmailContato22 As Integer = 144
Const ColContato23 As Integer = 145
Const ColTelefoneContato23 As Integer = 146
Const ColCelularContato23 As Integer = 147
Const ColCargoContato23 As Integer = 148
Const ColEmailContato23 As Integer = 149
Const ColContato24 As Integer = 150
Const ColTelefoneContato24 As Integer = 151
Const ColCelularContato24 As Integer = 152
Const ColCargoContato24 As Integer = 153
Const ColEmailContato24 As Integer = 154
Const ColContato25 As Integer = 155
Const ColTelefoneContato25 As Integer = 156
Const ColCelularContato25 As Integer = 157
Const ColCargoContato25 As Integer = 158
Const ColEmailContato25 As Integer = 159



Const colPendRelatorio As Integer = 225
Const colPendAprovacao As Integer = 226
Const colAnotacoes1 As Integer = 227
Const colAnotacoes2 As Integer = 228
Const colAnotacoes3 As Integer = 229
Const colAnotacoes4 As Integer = 230
Const colAnotacoes5 As Integer = 231


Const colFluxo As Integer = 53

Const indiceMinimo As Byte = 2
Const corDisabledTextBox As Long = -2147483633
Const corEnabledTextBox As Long = -2147483643
Const nomePlanilhaCadastro As String = "Clientes"

Private wsCadastro As Worksheet
Private wbCadastro As Workbook
Private indiceRegistro As Long

Private Sub btnCancelar_Click()
btnOK.Enabled = False
btnCancelar.Enabled = False
Call DesabilitaControles
Call CarregaDadosInicial
Call HabilitaBotoesAlteracao
End Sub

Private Sub btnobras_Click()
frmObras.Show

End Sub

Private Sub btnOK_Click()
Dim proximoId As Long

'Altera
If optAlterar.Value Then
Call SalvaRegistro(CLng(txtCodigoDoCliente.Text), indiceRegistro)

lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Novo
If optNovo.Value Then
proximoId = PegaProximoId
'pega a próxima linha
Dim proximoIndice As Long
'atualiza o arquivo para pegar o próximo registro atualizado
Call AtualizarArquivo(False)
proximoIndice = wsCadastro.UsedRange.Rows.Count + 1
Call SalvaRegistro(proximoId, proximoIndice)
txtCodigoDoCliente = proximoId
lblMensagem.Caption = "Registro salvo com sucesso"
End If
'Excluir
If optExcluir.Value Then
Dim result As VbMsgBoxResult
result = MsgBox("Deseja excluir o registro nº " & txtCodigoDoCliente.Text & " ?", vbYesNo, "Confirmação")

If result = vbYes Then
'abre o arquivo para escrita
Call AtualizarArquivo(False)
wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colCodigoDoCliente), wsCadastro.Cells(indiceRegistro, colCodigoDoCliente)).EntireRow.Delete
'salva
wbCadastro.Save
'abre somente leitura
Call AtualizarArquivo(True)
Call CarregaDadosInicial
lblMensagem.Caption = "Registro excluído com sucesso"
End If
End If

Call HabilitaBotoesAlteracao
Call DesabilitaControles

End Sub

Private Sub btnPesquisar_Click()
frmPesquisa.Show
End Sub

Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
btnobras.Visible = True
CheckBox1.Caption = "JÁ TEVE OBRA FABRICADA PELA AÇOTEC"
CheckBox1.Font.Bold = True
btnobras.SetFocus
Else
btnobras.Visible = False
CheckBox1.Caption = "NÃO POSSUI OBRA FABRICADA PELA AÇOTEC"
CheckBox1.Font.Bold = False

End If
End Sub



Private Sub Frame20_Click()

End Sub

Private Sub frmRegistro_Click()

End Sub

Private Sub Label177_Click()

End Sub

Private Sub Label202_Click()

End Sub

Private Sub Label205_Click()

End Sub

Private Sub Label208_Click()

End Sub

Private Sub Label228_Click()

End Sub

Private Sub Label244_Click()

End Sub

Private Sub Label257_Click()

End Sub

Private Sub Label260_Click()

End Sub

Private Sub Label270_Click()

End Sub

Private Sub Label296_Click()

End Sub

Private Sub frmCadastro_Click()

End Sub

Private Sub Label309_Click()

End Sub

Private Sub Label348_Click()

End Sub

Private Sub Label358_Click()

End Sub

Private Sub Label359_Click()

End Sub

Private Sub Label49_Click()

End Sub

Private Sub Label57_Click()

End Sub

Private Sub lblAnotacoes8_Click()

End Sub

Private Sub optAlterar_Click()
If txtCodigoDoCliente.Text <> vbNullString And txtCodigoDoCliente.Text <> "" Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
' txtCliente.SetFocus
Else
lblMensagem.Caption = "Não há registro a ser alterado"
End If
End Sub

Private Sub optExcluir_Click()
If txtCodigoDoCliente.Text <> vbNullString And txtCodigoDoCliente.Text <> "" Then
Call DesabilitaBotoesAlteracao
lblMensagem.Caption = "Modo de exclusão. Confira o dados do registro antes de excluí-lo"
Else
lblMensagem.Caption = "Não há registro a ser excluído"
End If
End Sub



Private Sub optNovo_Click()
Call LimpaControles
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
' txtCliente.SetFocus
End Sub



Private Sub TextBox202_Change()

End Sub

Private Sub TextBox39_Change()

End Sub

Private Sub txtCliente_Change()

End Sub

Private Sub txtPais_Change()

End Sub

Private Sub UserForm_Initialize()

Call DefinePlanilhaDados
Call HabilitaBotoesAlteracao
Call CarregaDadosInicial
Call DesabilitaControles

lblusuario.Caption = VBA.Environ("Username")
lblData.Caption = Date


End Sub

Private Sub btnAnterior_Click()
If indiceRegistro > indiceMinimo Then
indiceRegistro = indiceRegistro - 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If

End Sub

Private Sub btnPrimeiro_Click()
indiceRegistro = indiceMinimo
If indiceRegistro > 1 Then
Call CarregaRegistro
End If


End Sub

Private Sub btnProximo_Click()
If indiceRegistro < wsCadastro.UsedRange.Rows.Count Then
indiceRegistro = indiceRegistro + 1
End If
If indiceRegistro > 1 Then
Call CarregaRegistro
End If


End Sub

Private Sub btnUltimo_Click()
indiceRegistro = wsCadastro.UsedRange.Rows.Count
If indiceRegistro > 1 Then
Call CarregaRegistro
End If

End Sub

Private Sub CarregaDadosInicial()
indiceRegistro = 2
Call CarregaRegistro
End Sub

Private Sub CarregaRegistro()
'carrega os dados do primeiro registro
With wsCadastro
If Not IsEmpty(.Cells(indiceRegistro, colCodigoDoCliente)) Then
Me.txtCodigoDoCliente.Text = .Cells(indiceRegistro, colCodigoDoCliente).Value
Me.txtCliente.Text = .Cells(indiceRegistro, colCliente).Value

Me.ICliente.Text = .Cells(indiceRegistro, colCliente).Value
Me.IPEDIDO.Text = .Cells(indiceRegistro, colContato1).Value



End If
End With

Call AtualizaRegistroCorrente
End Sub

Public Sub CarregaRegistroPorIndice(ByVal indice As Long)
'carrega os dados do registro baseado no índice
indiceRegistro = indice

Call CarregaRegistro
End Sub

Private Sub AtualizarArquivo(ByVal ReadOnly As Boolean)
Dim caminhoCompleto As String
'fecha o arquivo de dados e tenta abrí-lo
'guarda o caminho
caminhoCompleto = wbCadastro.FullName
wbCadastro.Saved = True
wbCadastro.Close SaveChanges:=False

'abre o arquivo em modo escrita
Set wbCadastro = Workbooks.Open(Filename:=caminhoCompleto, ReadOnly:=ReadOnly)

'oculta a janela
wbCadastro.Windows(1).Visible = False

'reatribui a planilha de cadastro
Set wsCadastro = wbCadastro.Worksheets(nomePlanilhaCadastro)
End Sub

Private Sub SalvaRegistro(ByVal id As Long, ByVal indice As Long)
'tenta abrir o arquivo em modo escrita
Call AtualizarArquivo(False)

With wsCadastro
.Cells(indice, colCodigoDoCliente).Value = id
.Cells(indice, colCliente).Value = Me.txtCliente.Text
.Cells(indice, colEndereco).Value = Me.txtEndereco.Text
.Cells(indice, colBairro).Value = Me.txtBairro.Text
.Cells(indice, colCidade).Value = Me.txtCidade.Text
.Cells(indice, colUF).Value = Me.txtUF.Text
.Cells(indice, colCep).Value = Me.txtCep.Text
.Cells(indice, colPais).Value = Me.txtPais.Text
.Cells(indice, colDDD1).Value = Me.txtDDD1.Text
.Cells(indice, colTelefone1).Value = Me.txtTelefone1.Text
.Cells(indice, colDDD2).Value = Me.txtDDD2.Text
.Cells(indice, colTelefone2).Value = Me.txtTelefone2.Text
.Cells(indice, colSite).Value = Me.txtSite.Text
.Cells(indice, colModalidadeDoCliente).Value = Me.txtModalidadeDoCliente.Text
.Cells(indice, colCoordenador).Value = Me.txtCoordenador.Text
.Cells(indice, colRamalCoordenador).Value = Me.txtRamalCoordenador.Text
.Cells(indice, colEmailCoordenador).Value = Me.txtEmailCoordenador.Text
.Cells(indice, colCelularCoordenador).Value = Me.txtCelularCoordenador.Text
.Cells(indice, colProjetista).Value = Me.txtProjetista.Text
.Cells(indice, colRamalProjetista).Value = Me.txtRamalProjetista.Text
.Cells(indice, colEmailProjetista).Value = Me.txtEmailProjetista.Text
.Cells(indice, colCelularProjetista).Value = Me.txtCelularProjetista.Text
.Cells(indice, colVendedor).Value = Me.txtVendedor.Text
.Cells(indice, colRamalVendedor).Value = Me.txtRamalVendedor.Text
.Cells(indice, colEmailVendedor).Value = Me.txtEmailVendedor.Text
.Cells(indice, colCelularVendedor).Value = Me.TxtCelularVendedor.Text
.Cells(indice, colGestor).Value = Me.txtGestor.Text
.Cells(indice, colRamalGestor).Value = Me.txtRamalGestor.Text
.Cells(indice, colEmailGestor).Value = Me.txtEmailGestor.Text
.Cells(indice, colCelularGestor).Value = Me.txtCelularGestor.Text
.Cells(indice, colContato1).Value = Me.txtContato1.Text
.Cells(indice, colTelefoneContato1).Value = Me.txtTelefoneContato1.Text
.Cells(indice, colCelularContato1).Value = Me.txtCelularContato1.Text
.Cells(indice, colCargoContato1).Value = Me.txtCargoContato1.Text
.Cells(indice, colEmailContato1).Value = Me.txtEmailContato1.Text
.Cells(indice, colContato2).Value = Me.txtContato2.Text
.Cells(indice, colTelefoneContato2).Value = Me.txtTelefoneContato2.Text
.Cells(indice, colCelularContato2).Value = Me.txtCelularContato2.Text
.Cells(indice, colCargoContato2).Value = Me.txtCargoContato2.Text
.Cells(indice, colEmailContato2).Value = Me.txtEmailContato2.Text
.Cells(indice, colContato3).Value = Me.txtContato3.Text
.Cells(indice, colTelefoneContato3).Value = Me.txtTelefoneContato3.Text
.Cells(indice, colCelularContato3).Value = Me.txtCelularContato3.Text
.Cells(indice, colCargoContato3).Value = Me.txtCargoContato3.Text
.Cells(indice, colEmailContato3).Value = Me.txtEmailContato3.Text
.Cells(indice, colContato4).Value = Me.txtContato4.Text
.Cells(indice, colTelefoneContato4).Value = Me.txtTelefoneContato4.Text
.Cells(indice, colCelularContato4).Value = Me.txtCelularContato4.Text
.Cells(indice, colCargoContato4).Value = Me.txtCargoContato4.Text
.Cells(indice, colEmailContato4).Value = Me.txtEmailContato4.Text
.Cells(indice, colContato5).Value = Me.txtContato5.Text
.Cells(indice, colTelefoneContato5).Value = Me.txtTelefoneContato5.Text
.Cells(indice, colCelularContato5).Value = Me.txtCelularContato5.Text
.Cells(indice, colCargoContato5).Value = Me.txtCargoContato5.Text
.Cells(indice, colEmailContato5).Value = Me.txtEmailContato5.Text
.Cells(indice, colContato6).Value = Me.txtContato6.Text
.Cells(indice, colTelefoneContato6).Value = Me.txtTelefoneContato6.Text
.Cells(indice, colCelularContato6).Value = Me.txtCelularContato6.Text
.Cells(indice, colCargoContato6).Value = Me.txtCargoContato6.Text
.Cells(indice, colEmailContato6).Value = Me.txtEmailContato6.Text
.Cells(indice, colContato7).Value = Me.txtContato7.Text
.Cells(indice, colTelefoneContato7).Value = Me.txtTelefoneContato7.Text
.Cells(indice, colCelularContato7).Value = Me.txtCelularContato7.Text
.Cells(indice, colCargoContato7).Value = Me.txtCargoContato7.Text
.Cells(indice, colEmailContato7).Value = Me.txtEmailContato7.Text
.Cells(indice, ColContato8).Value = Me.txtContato8.Text
.Cells(indice, ColTelefoneContato8).Value = Me.txtTelefoneContato8.Text
.Cells(indice, ColCelularContato8).Value = Me.txtCelularContato8.Text
.Cells(indice, ColCargoContato8).Value = Me.txtCargoContato8.Text
.Cells(indice, ColEmailContato8).Value = Me.txtEmailContato8.Text
.Cells(indice, ColContato9).Value = Me.txtContato9.Text
.Cells(indice, ColTelefoneContato9).Value = Me.txtTelefoneContato9.Text
.Cells(indice, ColCelularContato9).Value = Me.txtCelularContato9.Text
.Cells(indice, ColCargoContato9).Value = Me.txtCargoContato9.Text
.Cells(indice, ColEmailContato9).Value = Me.txtEmailContato9.Text
.Cells(indice, ColContato10).Value = Me.txtContato10.Text
.Cells(indice, ColTelefoneContato10).Value = Me.txtTelefoneContato10.Text
.Cells(indice, ColCelularContato10).Value = Me.txtCelularContato10.Text
.Cells(indice, ColCargoContato10).Value = Me.txtCargoContato10.Text
.Cells(indice, ColEmailContato10).Value = Me.txtEmailContato10.Text
.Cells(indice, ColContato11).Value = Me.txtContato11.Text
.Cells(indice, ColTelefoneContato11).Value = Me.txtTelefoneContato11.Text
.Cells(indice, ColCelularContato11).Value = Me.txtCelularContato11.Text
.Cells(indice, ColCargoContato11).Value = Me.txtCargoContato11.Text
.Cells(indice, ColEmailContato11).Value = Me.txtEmailContato11.Text
.Cells(indice, ColContato12).Value = Me.txtContato12.Text
.Cells(indice, ColTelefoneContato12).Value = Me.txtTelefoneContato12.Text
.Cells(indice, ColCelularContato12).Value = Me.txtCelularContato12.Text
.Cells(indice, ColCargoContato12).Value = Me.txtCargoContato12.Text
.Cells(indice, ColEmailContato12).Value = Me.txtEmailContato12.Text
.Cells(indice, ColContato13).Value = Me.txtContato13.Text
.Cells(indice, ColTelefoneContato13).Value = Me.txtTelefoneContato13.Text
.Cells(indice, ColCelularContato13).Value = Me.txtCelularContato13.Text
.Cells(indice, ColCargoContato13).Value = Me.txtCargoContato13.Text
.Cells(indice, ColEmailContato13).Value = Me.txtEmailContato13.Text
.Cells(indice, ColContato14).Value = Me.txtContato14.Text
.Cells(indice, ColTelefoneContato14).Value = Me.txtTelefoneContato14.Text
.Cells(indice, ColCelularContato14).Value = Me.txtCelularContato14.Text
.Cells(indice, ColCargoContato14).Value = Me.txtCargoContato14.Text
.Cells(indice, ColEmailContato14).Value = Me.txtEmailContato14.Text
.Cells(indice, ColContato15).Value = Me.txtContato15.Text
.Cells(indice, ColTelefoneContato15).Value = Me.txtTelefoneContato15.Text
.Cells(indice, ColCelularContato15).Value = Me.txtCelularContato15.Text
.Cells(indice, ColCargoContato15).Value = Me.txtCargoContato15.Text
.Cells(indice, ColEmailContato15).Value = Me.txtEmailContato15.Text
.Cells(indice, ColContato16).Value = Me.txtContato16.Text
.Cells(indice, ColTelefoneContato16).Value = Me.txtTelefoneContato16.Text
.Cells(indice, ColCelularContato16).Value = Me.txtCelularContato16.Text
.Cells(indice, ColCargoContato16).Value = Me.txtCargoContato16.Text
.Cells(indice, ColEmailContato16).Value = Me.txtEmailContato16.Text
.Cells(indice, ColContato10).Value = Me.txtContato17.Text
.Cells(indice, ColTelefoneContato17).Value = Me.txtTelefoneContato17.Text
.Cells(indice, ColCelularContato17).Value = Me.txtCelularContato17.Text
.Cells(indice, ColCargoContato17).Value = Me.txtCargoContato17.Text
.Cells(indice, ColEmailContato17).Value = Me.txtEmailContato17.Text
.Cells(indice, ColContato18).Value = Me.txtContato18.Text
.Cells(indice, ColTelefoneContato18).Value = Me.txtTelefoneContato18.Text
.Cells(indice, ColCelularContato18).Value = Me.txtCelularContato18.Text
.Cells(indice, ColCargoContato18).Value = Me.txtCargoContato18.Text
.Cells(indice, ColEmailContato18).Value = Me.txtEmailContato18.Text
.Cells(indice, ColContato19).Value = Me.txtContato19.Text
.Cells(indice, ColTelefoneContato19).Value = Me.txtTelefoneContato19.Text
.Cells(indice, ColCelularContato19).Value = Me.txtCelularContato19.Text
.Cells(indice, ColCargoContato19).Value = Me.txtCargoContato19.Text
.Cells(indice, ColEmailContato19).Value = Me.txtEmailContato19.Text
.Cells(indice, ColContato20).Value = Me.txtContato20.Text
.Cells(indice, ColTelefoneContato20).Value = Me.txtTelefoneContato20.Text
.Cells(indice, ColCelularContato20).Value = Me.txtCelularContato20.Text
.Cells(indice, ColCargoContato20).Value = Me.txtCargoContato20.Text
.Cells(indice, ColEmailContato20).Value = Me.txtEmailContato20.Text
.Cells(indice, ColContato21).Value = Me.txtContato21.Text
.Cells(indice, ColTelefoneContato21).Value = Me.txtTelefoneContato21.Text
.Cells(indice, ColCelularContato21).Value = Me.txtCelularContato21.Text
.Cells(indice, ColCargoContato21).Value = Me.txtCargoContato21.Text
.Cells(indice, ColEmailContato21).Value = Me.txtEmailContato21.Text
.Cells(indice, ColContato22).Value = Me.txtContato22.Text
.Cells(indice, ColTelefoneContato22).Value = Me.txtTelefoneContato22.Text
.Cells(indice, ColCelularContato22).Value = Me.txtCelularContato22.Text
.Cells(indice, ColCargoContato22).Value = Me.txtCargoContato22.Text
.Cells(indice, ColEmailContato22).Value = Me.txtEmailContato22.Text
.Cells(indice, ColContato23).Value = Me.txtContato23.Text
.Cells(indice, ColTelefoneContato23).Value = Me.txtTelefoneContato23.Text
.Cells(indice, ColCelularContato23).Value = Me.txtCelularContato23.Text
.Cells(indice, ColCargoContato23).Value = Me.txtCargoContato23.Text
.Cells(indice, ColEmailContato23).Value = Me.txtEmailContato23.Text
.Cells(indice, ColContato24).Value = Me.txtContato24.Text
.Cells(indice, ColTelefoneContato24).Value = Me.txtTelefoneContato24.Text
.Cells(indice, ColCelularContato24).Value = Me.txtCelularContato24.Text
.Cells(indice, ColCargoContato24).Value = Me.txtCargoContato24.Text
.Cells(indice, ColEmailContato24).Value = Me.txtEmailContato24.Text
.Cells(indice, ColContato25).Value = Me.txtContato25.Text
.Cells(indice, ColTelefoneContato25).Value = Me.txtTelefoneContato25.Text
.Cells(indice, ColCelularContato25).Value = Me.txtCelularContato25.Text
.Cells(indice, ColCargoContato25).Value = Me.txtCargoContato25.Text
.Cells(indice, ColEmailContato25).Value = Me.txtEmailContato25.Text
.Cells(indice, colAnotacoes1).Value = Me.txtAnotacoes1.Text
.Cells(indice, colAnotacoes2).Value = Me.txtAnotacoes2.Text
.Cells(indice, colAnotacoes3).Value = Me.txtAnotacoes3.Text
.Cells(indice, colAnotacoes4).Value = Me.txtAnotacoes4.Text
.Cells(indice, colAnotacoes5).Value = Me.txtAnotacoes5.Text


End With

'salva o arquivo
Call wbCadastro.Save

'abre o arquivo novamente em modo leitura
Call AtualizarArquivo(True)

Call AtualizaRegistroCorrente
End Sub

Private Function PegaProximoId() As Long
Dim rangeIds As Range
'pega o range que se refere a toda a coluna do código (id)
Set rangeIds = wsCadastro.Range(wsCadastro.Cells(indiceMinimo, colCodigoDoCliente), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colCodigoDoCliente))
PegaProximoId = WorksheetFunction.Max(rangeIds) + 1
End Function

Private Sub AtualizaRegistroCorrente()
lblNavigator.Caption = indiceRegistro - 1 & " de " & wsCadastro.UsedRange.Rows.Count - 1
lblMensagem.Caption = ""
End Sub

Private Sub LimpaControles()

Me.txtCodigoDoCliente.Text = ""
Me.txtCliente.Text = ""
Me.txtEndereco.Text = ""
Me.txtBairro.Text = ""
Me.txtCidade.Text = ""
Me.txtUF.Text = ""
Me.txtCep.Text = ""
Me.txtPais.Text = ""
Me.txtDDD1.Text = ""
Me.txtTelefone1.Text = ""
Me.txtDDD2.Text = ""
Me.txtTelefone2.Text = ""
Me.txtSite.Text = ""
Me.txtCoordenador.Text = ""
Me.txtRamalCoordenador.Text = ""
Me.txtEmailCoordenador.Text = ""
Me.txtCelularCoordenador.Text = ""
Me.txtProjetista.Text = ""
Me.txtRamalProjetista.Text = ""
Me.txtEmailProjetista.Text = ""
Me.txtCelularProjetista.Text = ""
Me.txtVendedor.Text = ""
Me.txtRamalVendedor.Text = ""
Me.txtEmailVendedor.Text = ""
Me.TxtCelularVendedor.Text = ""
Me.txtGestor.Text = ""
Me.txtRamalGestor.Text = ""
Me.txtEmailGestor.Text = ""
Me.txtCelularGestor.Text = ""
Me.txtContato1.Text = ""
Me.txtTelefoneContato1.Text = ""
Me.txtCelularContato1.Text = ""
Me.txtCargoContato1.Text = ""
Me.txtEmailContato1.Text = ""
Me.txtContato2.Text = ""
Me.txtTelefoneContato2.Text = ""
Me.txtCelularContato2.Text = ""
Me.txtCargoContato2.Text = ""
Me.txtEmailContato2.Text = ""
Me.txtContato3.Text = ""
Me.txtTelefoneContato3.Text = ""
Me.txtCelularContato3.Text = ""
Me.txtCargoContato3.Text = ""
Me.txtEmailContato3.Text = ""
Me.txtContato4.Text = ""
Me.txtTelefoneContato4.Text = ""
Me.txtCelularContato4.Text = ""
Me.txtCargoContato4.Text = ""
Me.txtEmailContato4.Text = ""
Me.txtContato5.Text = ""
Me.txtTelefoneContato5.Text = ""
Me.txtCelularContato5.Text = ""
Me.txtCargoContato5.Text = ""
Me.txtEmailContato5.Text = ""
Me.txtContato6.Text = ""
Me.txtTelefoneContato6.Text = ""
Me.txtCelularContato6.Text = ""
Me.txtCargoContato6.Text = ""
Me.txtEmailContato6.Text = ""
Me.txtContato7.Text = ""
Me.txtTelefoneContato7.Text = ""
Me.txtCelularContato7.Text = ""
Me.txtCargoContato7.Text = ""
Me.txtEmailContato7.Text = ""
Me.txtContato8.Text = ""
Me.txtTelefoneContato8.Text = ""
Me.txtCelularContato8.Text = ""
Me.txtCargoContato8.Text = ""
Me.txtEmailContato8.Text = ""
Me.txtContato9.Text = ""
Me.txtTelefoneContato9.Text = ""
Me.txtCelularContato9.Text = ""
Me.txtCargoContato9.Text = ""
Me.txtEmailContato9.Text = ""
Me.txtContato10.Text = ""
Me.txtTelefoneContato10.Text = ""
Me.txtCelularContato10.Text = ""
Me.txtCargoContato10.Text = ""
Me.txtEmailContato10.Text = ""
Me.txtContato11.Text = ""
Me.txtTelefoneContato11.Text = ""
Me.txtCelularContato11.Text = ""
Me.txtCargoContato11.Text = ""
Me.txtEmailContato11.Text = ""
Me.txtContato12.Text = ""
Me.txtTelefoneContato12.Text = ""
Me.txtCelularContato12.Text = ""
Me.txtCargoContato12.Text = ""
Me.txtEmailContato12.Text = ""
Me.txtContato13.Text = ""
Me.txtTelefoneContato13.Text = ""
Me.txtCelularContato13.Text = ""
Me.txtCargoContato13.Text = ""
Me.txtEmailContato13.Text = ""
Me.txtContato14.Text = ""
Me.txtTelefoneContato14.Text = ""
Me.txtCelularContato14.Text = ""
Me.txtCargoContato14.Text = ""
Me.txtEmailContato14.Text = ""
Me.txtContato15.Text = ""
Me.txtTelefoneContato15.Text = ""
Me.txtCelularContato15.Text = ""
Me.txtCargoContato15.Text = ""
Me.txtEmailContato15.Text = ""
Me.txtContato16.Text = ""
Me.txtTelefoneContato16.Text = ""
Me.txtCelularContato16.Text = ""
Me.txtCargoContato16.Text = ""
Me.txtEmailContato16.Text = ""
Me.txtContato17.Text = ""
Me.txtTelefoneContato17.Text = ""
Me.txtCelularContato17.Text = ""
Me.txtCargoContato17.Text = ""
Me.txtEmailContato17.Text = ""
Me.txtContato18.Text = ""
Me.txtTelefoneContato18.Text = ""
Me.txtCelularContato18.Text = ""
Me.txtCargoContato18.Text = ""
Me.txtEmailContato18.Text = ""
Me.txtContato19.Text = ""
Me.txtTelefoneContato19.Text = ""
Me.txtCelularContato19.Text = ""
Me.txtCargoContato19.Text = ""
Me.txtEmailContato19.Text = ""
Me.txtContato20.Text = ""
Me.txtTelefoneContato20.Text = ""
Me.txtCelularContato20.Text = ""
Me.txtCargoContato20.Text = ""
Me.txtEmailContato20.Text = ""
Me.txtContato21.Text = ""
Me.txtTelefoneContato21.Text = ""
Me.txtCelularContato21.Text = ""
Me.txtCargoContato21.Text = ""
Me.txtEmailContato21.Text = ""
Me.txtContato22.Text = ""
Me.txtTelefoneContato22.Text = ""
Me.txtCelularContato22.Text = ""
Me.txtCargoContato22.Text = ""
Me.txtEmailContato22.Text = ""
Me.txtContato23.Text = ""
Me.txtTelefoneContato23.Text = ""
Me.txtCelularContato23.Text = ""
Me.txtCargoContato23.Text = ""
Me.txtEmailContato23.Text = ""
Me.txtContato24.Text = ""
Me.txtTelefoneContato24.Text = ""
Me.txtCelularContato24.Text = ""
Me.txtCargoContato24.Text = ""
Me.txtEmailContato24.Text = ""
Me.txtContato25.Text = ""
Me.txtTelefoneContato25.Text = ""
Me.txtCelularContato25.Text = ""
Me.txtCargoContato25.Text = ""
Me.txtEmailContato25.Text = ""
Me.txtAnotacoes1.Text = ""
Me.txtAnotacoes2.Text = ""
Me.txtAnotacoes3.Text = ""
Me.txtAnotacoes4.Text = ""
Me.txtAnotacoes5.Text = ""

End Sub

Private Sub HabilitaControles()
'Me.txtCodigoDoCliente.Locked = False
Me.txtCliente.Locked = False
Me.txtEndereco.Locked = False
Me.txtBairro.Locked = False
Me.txtCidade.Locked = False
Me.txtUF.Locked = False
Me.txtCep.Locked = False
Me.txtPais.Locked = False
Me.txtDDD1.Locked = False
Me.txtTelefone1.Locked = False
Me.txtDDD2.Locked = False
Me.txtTelefone2.Locked = False
Me.txtSite.Locked = False
Me.txtModalidadeDoCliente.Locked = False
Me.txtCoordenador.Locked = False
Me.txtRamalCoordenador.Locked = False
Me.txtEmailCoordenador.Locked = False
Me.txtCelularCoordenador.Locked = False
Me.txtProjetista.Locked = False
Me.txtRamalProjetista.Locked = False
Me.txtEmailProjetista.Locked = False
Me.txtCelularProjetista.Locked = False
Me.txtVendedor.Locked = False
Me.txtRamalVendedor.Locked = False
Me.txtEmailVendedor.Locked = False
Me.TxtCelularVendedor.Locked = False
Me.txtGestor.Locked = False
Me.txtRamalGestor.Locked = False
Me.txtEmailGestor.Locked = False
Me.txtCelularGestor.Locked = False
Me.txtContato1.Locked = False
Me.txtTelefoneContato1.Locked = False
Me.txtCelularContato1.Locked = False
Me.txtCargoContato1.Locked = False
Me.txtEmailContato1.Locked = False
Me.txtContato2.Locked = False
Me.txtTelefoneContato2.Locked = False
Me.txtCelularContato2.Locked = False
Me.txtCargoContato2.Locked = False
Me.txtEmailContato2.Locked = False
Me.txtContato3.Locked = False
Me.txtTelefoneContato3.Locked = False
Me.txtCelularContato3.Locked = False
Me.txtCargoContato3.Locked = False
Me.txtEmailContato3.Locked = False
Me.txtContato4.Locked = False
Me.txtTelefoneContato4.Locked = False
Me.txtCelularContato4.Locked = False
Me.txtCargoContato4.Locked = False
Me.txtEmailContato4.Locked = False
Me.txtContato5.Locked = False
Me.txtTelefoneContato5.Locked = False
Me.txtCelularContato5.Locked = False
Me.txtCargoContato5.Locked = False
Me.txtEmailContato5.Locked = False
Me.txtContato6.Locked = False
Me.txtTelefoneContato6.Locked = False
Me.txtCelularContato6.Locked = False
Me.txtCargoContato6.Locked = False
Me.txtEmailContato6.Locked = False
Me.txtContato7.Locked = False
Me.txtTelefoneContato7.Locked = False
Me.txtCelularContato7.Locked = False
Me.txtCargoContato7.Locked = False
Me.txtEmailContato7.Locked = False
Me.txtContato8.Locked = False
Me.txtTelefoneContato8.Locked = False
Me.txtCelularContato8.Locked = False
Me.txtCargoContato8.Locked = False
Me.txtEmailContato8.Locked = False
Me.txtContato9.Locked = False
Me.txtTelefoneContato9.Locked = False
Me.txtCelularContato9.Locked = False
Me.txtCargoContato9.Locked = False
Me.txtEmailContato9.Locked = False
Me.txtContato10.Locked = False
Me.txtTelefoneContato10.Locked = False
Me.txtCelularContato10.Locked = False
Me.txtCargoContato10.Locked = False
Me.txtEmailContato10.Locked = False
Me.txtContato11.Locked = False
Me.txtTelefoneContato11.Locked = False
Me.txtCelularContato11.Locked = False
Me.txtCargoContato11.Locked = False
Me.txtEmailContato11.Locked = False
Me.txtContato12.Locked = False
Me.txtTelefoneContato12.Locked = False
Me.txtCelularContato12.Locked = False
Me.txtCargoContato12.Locked = False
Me.txtEmailContato12.Locked = False
Me.txtContato13.Locked = False
Me.txtTelefoneContato13.Locked = False
Me.txtCelularContato13.Locked = False
Me.txtCargoContato13.Locked = False
Me.txtEmailContato13.Locked = False
Me.txtContato14.Locked = False
Me.txtTelefoneContato14.Locked = False
Me.txtCelularContato14.Locked = False
Me.txtCargoContato14.Locked = False
Me.txtEmailContato14.Locked = False
Me.txtContato15.Locked = False
Me.txtTelefoneContato15.Locked = False
Me.txtCelularContato15.Locked = False
Me.txtCargoContato15.Locked = False
Me.txtEmailContato15.Locked = False
Me.txtContato16.Locked = False
Me.txtTelefoneContato16.Locked = False
Me.txtCelularContato16.Locked = False
Me.txtCargoContato16.Locked = False
Me.txtEmailContato16.Locked = False
Me.txtContato17.Locked = False
Me.txtTelefoneContato17.Locked = False
Me.txtCelularContato17.Locked = False
Me.txtCargoContato17.Locked = False
Me.txtEmailContato17.Locked = False
Me.txtContato18.Locked = False
Me.txtTelefoneContato18.Locked = False
Me.txtCelularContato18.Locked = False
Me.txtCargoContato18.Locked = False
Me.txtEmailContato18.Locked = False
Me.txtContato19.Locked = False
Me.txtTelefoneContato19.Locked = False
Me.txtCelularContato19.Locked = False
Me.txtCargoContato19.Locked = False
Me.txtEmailContato19.Locked = False
Me.txtContato20.Locked = False
Me.txtTelefoneContato20.Locked = False
Me.txtCelularContato20.Locked = False
Me.txtCargoContato20.Locked = False
Me.txtEmailContato20.Locked = False
Me.txtContato21.Locked = False
Me.txtTelefoneContato21.Locked = False
Me.txtCelularContato21.Locked = False
Me.txtCargoContato21.Locked = False
Me.txtEmailContato21.Locked = False
Me.txtContato22.Locked = False
Me.txtTelefoneContato22.Locked = False
Me.txtCelularContato22.Locked = False
Me.txtCargoContato22.Locked = False
Me.txtEmailContato22.Locked = False
Me.txtContato23.Locked = False
Me.txtTelefoneContato23.Locked = False
Me.txtCelularContato23.Locked = False
Me.txtCargoContato23.Locked = False
Me.txtEmailContato23.Locked = False
Me.txtContato24.Locked = False
Me.txtTelefoneContato24.Locked = False
Me.txtCelularContato24.Locked = False
Me.txtCargoContato24.Locked = False
Me.txtEmailContato24.Locked = False
Me.txtContato25.Locked = False
Me.txtTelefoneContato25.Locked = False
Me.txtCelularContato25.Locked = False
Me.txtCargoContato25.Locked = False
Me.txtEmailContato25.Locked = False
Me.txtAnotacoes1.Locked = False
Me.txtAnotacoes2.Locked = False
Me.txtAnotacoes3.Locked = False
Me.txtAnotacoes4.Locked = False
Me.txtAnotacoes5.Locked = False



Me.txtCodigoDoCliente.BackColor = corEnabledTextBox
Me.txtCliente.BackColor = corEnabledTextBox
Me.txtEndereco.BackColor = corEnabledTextBox
Me.txtBairro.BackColor = corEnabledTextBox
Me.txtCidade.BackColor = corEnabledTextBox
Me.txtUF.BackColor = corEnabledTextBox
Me.txtCep.BackColor = corEnabledTextBox
Me.txtPais.BackColor = corEnabledTextBox
Me.txtDDD1.BackColor = corEnabledTextBox
Me.txtTelefone1.BackColor = corEnabledTextBox
Me.txtDDD2.BackColor = corEnabledTextBox
Me.txtTelefone2.BackColor = corEnabledTextBox
Me.txtSite.BackColor = corEnabledTextBox
Me.txtCoordenador.BackColor = corEnabledTextBox
Me.txtRamalCoordenador.BackColor = corEnabledTextBox
Me.txtEmailCoordenador.BackColor = corEnabledTextBox
Me.txtCelularCoordenador.BackColor = corEnabledTextBox
Me.txtProjetista.BackColor = corEnabledTextBox
Me.txtRamalProjetista.BackColor = corEnabledTextBox
Me.txtEmailProjetista.BackColor = corEnabledTextBox
Me.txtCelularProjetista.BackColor = corEnabledTextBox
Me.txtVendedor.BackColor = corEnabledTextBox
Me.txtRamalVendedor.BackColor = corEnabledTextBox
Me.txtEmailVendedor.BackColor = corEnabledTextBox
Me.TxtCelularVendedor.BackColor = corEnabledTextBox
Me.txtGestor.BackColor = corEnabledTextBox
Me.txtRamalGestor.BackColor = corEnabledTextBox
Me.txtEmailGestor.BackColor = corEnabledTextBox
Me.txtCelularGestor.BackColor = corEnabledTextBox
Me.txtContato1.BackColor = corEnabledTextBox
Me.txtTelefoneContato1.BackColor = corEnabledTextBox
Me.txtCelularContato1.BackColor = corEnabledTextBox
Me.txtCargoContato1.BackColor = corEnabledTextBox
Me.txtEmailContato1.BackColor = corEnabledTextBox
Me.txtContato2.BackColor = corEnabledTextBox
Me.txtTelefoneContato2.BackColor = corEnabledTextBox
Me.txtCelularContato2.BackColor = corEnabledTextBox
Me.txtCargoContato2.BackColor = corEnabledTextBox
Me.txtEmailContato2.BackColor = corEnabledTextBox
Me.txtContato3.BackColor = corEnabledTextBox
Me.txtTelefoneContato3.BackColor = corEnabledTextBox
Me.txtCelularContato3.BackColor = corEnabledTextBox
Me.txtCargoContato3.BackColor = corEnabledTextBox
Me.txtEmailContato3.BackColor = corEnabledTextBox
Me.txtContato4.BackColor = corEnabledTextBox
Me.txtTelefoneContato4.BackColor = corEnabledTextBox
Me.txtCelularContato4.BackColor = corEnabledTextBox
Me.txtCargoContato4.BackColor = corEnabledTextBox
Me.txtEmailContato4.BackColor = corEnabledTextBox
Me.txtContato5.BackColor = corEnabledTextBox
Me.txtTelefoneContato5.BackColor = corEnabledTextBox
Me.txtCelularContato5.BackColor = corEnabledTextBox
Me.txtCargoContato5.BackColor = corEnabledTextBox
Me.txtEmailContato5.BackColor = corEnabledTextBox
Me.txtContato6.BackColor = corEnabledTextBox
Me.txtTelefoneContato6.BackColor = corEnabledTextBox
Me.txtCelularContato6.BackColor = corEnabledTextBox
Me.txtCargoContato6.BackColor = corEnabledTextBox
Me.txtEmailContato6.BackColor = corEnabledTextBox
Me.txtContato7.BackColor = corEnabledTextBox
Me.txtTelefoneContato7.BackColor = corEnabledTextBox
Me.txtCelularContato7.BackColor = corEnabledTextBox
Me.txtCargoContato7.BackColor = corEnabledTextBox
Me.txtEmailContato7.BackColor = corEnabledTextBox
Me.txtContato8.BackColor = corEnabledTextBox
Me.txtTelefoneContato8.BackColor = corEnabledTextBox
Me.txtCelularContato8.BackColor = corEnabledTextBox
Me.txtCargoContato8.BackColor = corEnabledTextBox
Me.txtEmailContato8.BackColor = corEnabledTextBox
Me.txtContato9.BackColor = corEnabledTextBox
Me.txtTelefoneContato9.BackColor = corEnabledTextBox
Me.txtCelularContato9.BackColor = corEnabledTextBox
Me.txtCargoContato9.BackColor = corEnabledTextBox
Me.txtEmailContato9.BackColor = corEnabledTextBox
Me.txtContato10.BackColor = corEnabledTextBox
Me.txtTelefoneContato10.BackColor = corEnabledTextBox
Me.txtCelularContato10.BackColor = corEnabledTextBox
Me.txtCargoContato10.BackColor = corEnabledTextBox
Me.txtEmailContato10.BackColor = corEnabledTextBox
Me.txtContato11.BackColor = corEnabledTextBox
Me.txtTelefoneContato11.BackColor = corEnabledTextBox
Me.txtCelularContato11.BackColor = corEnabledTextBox
Me.txtCargoContato11.BackColor = corEnabledTextBox
Me.txtEmailContato11.BackColor = corEnabledTextBox
Me.txtContato12.BackColor = corEnabledTextBox
Me.txtTelefoneContato12.BackColor = corEnabledTextBox
Me.txtCelularContato12.BackColor = corEnabledTextBox
Me.txtCargoContato12.BackColor = corEnabledTextBox
Me.txtEmailContato12.BackColor = corEnabledTextBox
Me.txtContato13.BackColor = corEnabledTextBox
Me.txtTelefoneContato13.BackColor = corEnabledTextBox
Me.txtCelularContato13.BackColor = corEnabledTextBox
Me.txtCargoContato13.BackColor = corEnabledTextBox
Me.txtEmailContato13.BackColor = corEnabledTextBox
Me.txtContato14.BackColor = corEnabledTextBox
Me.txtTelefoneContato14.BackColor = corEnabledTextBox
Me.txtCelularContato14.BackColor = corEnabledTextBox
Me.txtCargoContato14.BackColor = corEnabledTextBox
Me.txtEmailContato14.BackColor = corEnabledTextBox
Me.txtContato15.BackColor = corEnabledTextBox
Me.txtTelefoneContato15.BackColor = corEnabledTextBox
Me.txtCelularContato15.BackColor = corEnabledTextBox
Me.txtCargoContato15.BackColor = corEnabledTextBox
Me.txtEmailContato15.BackColor = corEnabledTextBox
Me.txtContato16.BackColor = corEnabledTextBox
Me.txtTelefoneContato16.BackColor = corEnabledTextBox
Me.txtCelularContato16.BackColor = corEnabledTextBox
Me.txtCargoContato16.BackColor = corEnabledTextBox
Me.txtEmailContato16.BackColor = corEnabledTextBox
Me.txtContato17.BackColor = corEnabledTextBox
Me.txtTelefoneContato17.BackColor = corEnabledTextBox
Me.txtCelularContato17.BackColor = corEnabledTextBox
Me.txtCargoContato17.BackColor = corEnabledTextBox
Me.txtEmailContato17.BackColor = corEnabledTextBox
Me.txtContato18.BackColor = corEnabledTextBox
Me.txtTelefoneContato18.BackColor = corEnabledTextBox
Me.txtCelularContato18.BackColor = corEnabledTextBox
Me.txtCargoContato18.BackColor = corEnabledTextBox
Me.txtEmailContato18.BackColor = corEnabledTextBox
Me.txtContato19.BackColor = corEnabledTextBox
Me.txtTelefoneContato19.BackColor = corEnabledTextBox
Me.txtCelularContato19.BackColor = corEnabledTextBox
Me.txtCargoContato19.BackColor = corEnabledTextBox
Me.txtEmailContato19.BackColor = corEnabledTextBox
Me.txtContato20.BackColor = corEnabledTextBox
Me.txtTelefoneContato20.BackColor = corEnabledTextBox
Me.txtCelularContato20.BackColor = corEnabledTextBox
Me.txtCargoContato20.BackColor = corEnabledTextBox
Me.txtEmailContato20.BackColor = corEnabledTextBox
Me.txtContato21.BackColor = corEnabledTextBox
Me.txtTelefoneContato21.BackColor = corEnabledTextBox
Me.txtCelularContato21.BackColor = corEnabledTextBox
Me.txtCargoContato21.BackColor = corEnabledTextBox
Me.txtEmailContato21.BackColor = corEnabledTextBox
Me.txtContato22.BackColor = corEnabledTextBox
Me.txtTelefoneContato22.BackColor = corEnabledTextBox
Me.txtCelularContato22.BackColor = corEnabledTextBox
Me.txtCargoContato22.BackColor = corEnabledTextBox
Me.txtEmailContato22.BackColor = corEnabledTextBox
Me.txtContato23.BackColor = corEnabledTextBox
Me.txtTelefoneContato23.BackColor = corEnabledTextBox
Me.txtCelularContato23.BackColor = corEnabledTextBox
Me.txtCargoContato23.BackColor = corEnabledTextBox
Me.txtEmailContato23.BackColor = corEnabledTextBox
Me.txtContato24.BackColor = corEnabledTextBox
Me.txtTelefoneContato24.BackColor = corEnabledTextBox
Me.txtCelularContato24.BackColor = corEnabledTextBox
Me.txtCargoContato24.BackColor = corEnabledTextBox
Me.txtEmailContato24.BackColor = corEnabledTextBox
Me.txtContato25.BackColor = corEnabledTextBox
Me.txtTelefoneContato25.BackColor = corEnabledTextBox
Me.txtCelularContato25.BackColor = corEnabledTextBox
Me.txtCargoContato25.BackColor = corEnabledTextBox
Me.txtEmailContato25.BackColor = corEnabledTextBox
Me.txtAnotacoes1.BackColor = corEnabledTextBox
Me.txtAnotacoes2.BackColor = corEnabledTextBox
Me.txtAnotacoes3.BackColor = corEnabledTextBox
Me.txtAnotacoes4.BackColor = corEnabledTextBox
Me.txtAnotacoes5.BackColor = corEnabledTextBox



End Sub

Private Sub DesabilitaControles()
'Me.txtCodigoDoCliente.Locked = True
Me.txtCliente.Locked = True
Me.txtContato1.Locked = True

'______________________________________________________

Me.txtCodigoDoCliente.BackColor = corDisabledTextBox




End Sub

Private Sub HabilitaBotoesAlteracao()
'habilita os botões de alteração
optAlterar.Enabled = True
optExcluir.Enabled = True
optNovo.Enabled = True
btnPesquisar.Enabled = True
btnOK.Enabled = False
btnCancelar.Enabled = False

'limpa os valores dos controles
optAlterar.Value = False
optExcluir.Value = False
optNovo.Value = False
End Sub

Private Sub DesabilitaBotoesAlteracao()
'desabilita os botões de alteração
optAlterar.Enabled = False
optExcluir.Enabled = False
optNovo.Enabled = False
btnPesquisar.Enabled = False
btnOK.Enabled = True
btnCancelar.Enabled = True
End Sub

Public Function ProcuraIndiceRegistroPodId(ByVal id As Long) As Long
Dim i As Long
Dim retorno As Long
Dim encontrado As Boolean

i = indiceMinimo
With wsCadastro
Do While Not IsEmpty(.Cells(i, colCodigoDoCliente))
If .Cells(i, colCodigoDoCliente).Value = id Then
retorno = i
encontrado = True
Exit Do
End If
i = i + 1
Loop
End With

'caso não encontre o registro, retorna -1
If Not encontrado Then
retorno = -1
End If

ProcuraIndiceRegistroPodId = i
End Function

Private Sub DefinePlanilhaDados()
Dim abrirArquivo As Boolean
Dim wb As Workbook
Dim caminhoCompleto As String
Dim ARQUIVO_DADOS As String
Dim PASTA_DADOS As String

abrirArquivo = True

ARQUIVO_DADOS = Range("ARQUIVO_DADOS").Value
PASTA_DADOS = Range("PASTA_DADOS").Value

If ThisWorkbook.Name <> ARQUIVO_DADOS Then
'monta a string do caminho completo
If PASTA_DADOS = vbNullString Or PASTA_DADOS = "" Then
caminhoCompleto = Replace(ThisWorkbook.FullName, ThisWorkbook.Name, vbNullString) & ARQUIVO_DADOS
Else
If Right(PASTA_DADOS, 1) = "\" Then
caminhoCompleto = PASTA_DADOS & ARQUIVO_DADOS
Else
caminhoCompleto = PASTA_DADOS & "\" & ARQUIVO_DADOS
End If
End If

'verifica se o arquivo não está aberto
For Each wb In Application.Workbooks
If wb.Name = ARQUIVO_DADOS Then
abrirArquivo = False
Exit For
End If
Next

'atribui o arquivo
If abrirArquivo Then
Set wbCadastro = Workbooks.Open(Filename:=caminhoCompleto, ReadOnly:=True)
Else
Set wbCadastro = Workbooks(ARQUIVO_DADOS)
End If
Else
Set wbCadastro = ThisWorkbook
End If

Set wsCadastro = wbCadastro.Worksheets(nomePlanilhaCadastro)

'oculta o arquivo de dados
wbCadastro.Windows(1).Visible = False

End Sub

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'fecha a planilha de dados, se estiver aberta
If Not wbCadastro Is Nothing Then
wbCadastro.Saved = True
wbCadastro.Close SaveChanges:=False
End If

Set wbCadastro = Nothing
End Sub

Rafael Monteiro

22-05-2013 14:47:47

Aline,

esse tipo de erro costuma ocorrer as vezes por causa de um detalhe bem simples porém difícil de identificar.

Me envie sua planilha que eu dou uma olhada, talvez eu possa te ajudar.

AlineMartins

23-05-2013 18:10:47

Boa tarde Rafael,

Segue abaixo o Cadastro adaptado.
Cadastro_de_Clientes.rar
Se reparar ele está puxando as informações do ultimo cadastro feito e não está salvando os mesmos.

Muito obrigada pela ajuda.

Abraço

Rafael Monteiro

24-05-2013 18:02:26

Aline,

Vou verificar com calma aí eu te informo.

Abs.

AlineMartins

24-05-2013 18:21:35

Muito obrigada Rafael!!

Bjs

Rafael Monteiro

29-05-2013 13:51:36

Oi Aline,

Verifiquei o seu projeto e tem alguns bags pra resolver. preciso de algumas informações adicionais, entre em contato pelo e mail: [REMOVIDO].

---------------------------------------------------------------
Correto Tomás, valeu.
---------------------------------------------------------------

Aline enviei o e mail para vc entrar em contato.


Abs.

webmaster

29-05-2013 15:28:10

Pessoal,

Evitem expor contatos pessoais. Como os tópicos são públicos, são um belo alvo de spammers e crackers. Isso sobrecarrega o fórum, além de prejudicar o referido contato.

Para isso, usem mensagens particulares, ok?

Abraços

Adrianozagnoli

19-06-2013 15:36:57

Olá a todos!
Encontrei um erro neste aplicativo e gostaria de saber se alguém sabe a solução. Verifique que ele faz corretamente a alteração de fornecedor, cadastro entre outros. Porém, ao fazer um novo cadastro, eu faço uma pesquisa e ele está lá. Ao clicar duas vezes para abrir o cadastro, ele não traz as informações corretas do novo cadastro feito e sim dos que já tinha na planilha original.

Alguém sabe como resolver o problema?

brasil

06-09-2013 18:35:11

Prezados,
Boa tarde!

Adorei a planilha de cadastro e adaptei ela para uso ao meu trabalho. Porém estou com problemas quando vou fazer a pesquisa, alguém poderia me ajudar por favor?

Agradeço imensamente

[REMOVIDO]

webmaster

06-09-2013 19:56:22

Colega,

Conforme as regras do fórum, não é permitida publicação de links para sites de downloads, como o sendspace. O fórum conta com o a funcionalidade de poder incluir anexos nos tópicos para facilitar o compartilhamento de arquivos. Peço que use esta funcionalidade para tal.

Abraços

brasil

06-09-2013 20:20:04

Opa desculpe amigo, coloquei em link pois não estava conseguindo anexar porque não tinha zipada rs.

Agora foi.

Se alguém poder me ajudar no erro :(

brasil

08-09-2013 22:01:50

Ningém tem uma solução? :(