erro 2110...Help me.

CJLEUTZ

08-10-2015 19:06:28

Private Sub optAlterar_Click()
If txtCodigo.Text <> vbNullString And txtCodigo.Text <> "" Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
txtRazao.SetFocus......................." nao é possivel mover o foco para o controle por que esta invisivel"
Else
lblMensagem.Caption = "Não há registro a ser alterado"
End If
End Sub

webmaster

13-10-2015 13:43:21

Colega,

" nao é possivel mover o foco para o controle por que esta invisivel"

Não dá para ser mais claro que isso....

CJLEUTZ

13-10-2015 15:42:52

webmaster escreveu:Colega,

" nao é possivel mover o foco para o controle por que esta invisivel"

Não dá para ser mais claro que isso....
Você poderia exemplificar não consigo enxergar o erro... Obrigado :D

Reinaldo

13-10-2015 18:20:50

Sem ver o seu formulario, podemos entender que tenta selecionar um controle (txtRazao.SetFocus) porem esse controle está oculto/invisivel; é o mesmo (se já brincou de esconde esconde) que tentar pegar alguém que está se escondendo, primeiro é preciso achar esse alguém.
Verifique se o nome do controle que deseja o Foco e o TxtRazão, se verifique a possibilidade de incluir-lo na rotina HabilitaControles ou inclua a linha/comando de habilitação antes do setfocus;ou ainda comente (incluir um apostrofe simples no inicio da linha) a linha do comando setfocus.

CJLEUTZ

14-10-2015 14:35:49

Reinaldo escreveu:Sem ver o seu formulario, podemos entender que tenta selecionar um controle (txtRazao.SetFocus) porem esse controle está oculto/invisivel; é o mesmo (se já brincou de esconde esconde) que tentar pegar alguém que está se escondendo, primeiro é preciso achar esse alguém.
Verifique se o nome do controle que deseja o Foco e o TxtRazão, se verifique a possibilidade de incluir-lo na rotina HabilitaControles ou inclua a linha/comando de habilitação antes do setfocus;ou ainda comente (incluir um apostrofe simples no inicio da linha) a linha do comando setfocus.


veja se voce consegue detectar o erro, pois ja quebrei a cabeça e nao achei... sou novato neste assunto, mas tentei....
Option Explicit

Const colCodigo As Integer = 1
Const colRazao As Integer = 2
Const colEmpresa As Integer = 3
Const colEst As Integer = 4
Const colFuncionario As Integer = 5
Const colRa As Integer = 6
Const colGr As Integer = 7
Const colCnpj As Integer = 8
Const colCnae As Integer = 9
Const colLaudoVibratorio As Integer = 10
Const colRealizado As Integer = 11
Const colPa As Integer = 12
Const colPpra As Integer = 13
Const colVal1 As Integer = 14
Const colPcmso As Integer = 15
Const colVal2 As Integer = 16

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(txtCodigo.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)
txtCodigo = 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º " & txtCodigo.Text & " ?", vbYesNo, "Confirmação")

If result = vbYes Then
wsCadastro.Range(wsCadastro.Cells(indiceRegistro, colCodigo), wsCadastro.Cells(indiceRegistro, colCodigo)).EntireRow.Delete
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 txtCodigo.Text <> vbNullString And txtCodigo.Text <> "" Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
txtRazao.SetFocus
Else
lblMensagem.Caption = "Não há registro a ser alterado"
End If
End Sub

Private Sub optExcluir_Click()
If txtCodigo.Text <> vbNullString And txtCodigo.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
txtRazao.SetFocus
End Sub

Private Sub UserForm_Initialize()
Set wsCadastro = ThisWorkbook.Worksheets("Dados")
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()
'mexi aki
indiceRegistro = 2
Call CarregaRegistro
End Sub

Private Sub CarregaRegistro()
'carrega os dados do primeiro registro
With wsCadastro
If Not IsEmpty(.Cells(indiceRegistro, colEmpresa)) Then
Me.txtCodigo.Text = .Cells(indiceRegistro, colCodigo).Value
Me.txtRazao.Text = .Cells(indiceRegistro, colRazao).Value
Me.txtempresa.Text = .Cells(indiceRegistro, colEmpresa).Value
Me.TxtEst.Text = .Cells(indiceRegistro, colEst).Value
Me.Txtfuncionario.Text = .Cells(indiceRegistro, colFuncionario).Value
Me.TxtRA.Text = .Cells(indiceRegistro, colRa).Value
Me.TxtGR.Text = .Cells(indiceRegistro, colGr).Value
Me.TxtCnpj.Text = .Cells(indiceRegistro, colCnpj).Value
Me.TxtCnae.Text = .Cells(indiceRegistro, colCnae).Value
Me.TxtLaudoVibratorio.Text = .Cells(indiceRegistro, colLaudoVibratorio).Value
Me.Txtrealizado.Text = .Cells(indiceRegistro, colRealizado).Value
Me.TxtPa.Text = .Cells(indiceRegistro, colPa).Value
Me.Txtppra.Text = .Cells(indiceRegistro, colPpra).Value
Me.txtval1.Text = .Cells(indiceRegistro, colVal1).Value
Me.Txtpcmso.Text = .Cells(indiceRegistro, colPcmso).Value
Me.txtval2.Text = .Cells(indiceRegistro, colVal2).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, colCodigo).Value = id
.Cells(indice, colRazao).Value = Me.txtRazao.Text
.Cells(indice, colEmpresa).Value = Me.txtempresa.Text
.Cells(indice, colEst).Value = Me.TxtEst.Text
.Cells(indice, colFuncionario).Value = Me.Txtfuncionario.Text
.Cells(indice, colRa).Value = Me.TxtRA.Text
.Cells(indice, colGr).Value = Me.TxtGR.Text
.Cells(indice, colCnpj).Value = Me.TxtCnpj.Text
.Cells(indice, colCnae).Value = Me.TxtCnae.Text
.Cells(indice, colLaudoVibratorio).Value = Me.TxtLaudoVibratorio.Text
.Cells(indice, colRealizado).Value = Me.Txtrealizado.Text
.Cells(indice, colPa).Value = Me.TxtPa.Text
.Cells(indice, colPpra).Value = Me.Txtppra.Text
.Cells(indice, colPcmso).Value = Me.Txtpcmso.Text

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, colCodigo), wsCadastro.Cells(wsCadastro.UsedRange.Rows.Count, colCodigo))
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.txtCodigo.Text = ""
Me.txtRazao.Text = ""
Me.txtempresa.Text = ""
Me.TxtEst.Text = ""
Me.Txtfuncionario.Text = ""
Me.TxtRA.Text = ""
Me.TxtGR.Text = ""
Me.TxtCnpj.Text = ""
Me.TxtCnae.Text = ""
Me.Txtppra.Text = ""
Me.TxtPa.Text = ""
Me.Txtpcmso.Text = ""
Me.TxtLaudoVibratorio.Text = ""
Me.Txtrealizado.Text = ""

End Sub

Private Sub HabilitaControles()
'Me.txtCodigo.Locked = False
Me.txtRazao.Locked = False
Me.txtempresa.Locked = False
Me.TxtEst.Locked = False
Me.Txtfuncionario.Locked = False
Me.TxtRA.Locked = False
Me.TxtGR.Locked = False
Me.TxtCnpj.Locked = False
Me.TxtCnae.Locked = False
Me.TxtPa.Locked = False
Me.Txtppra.Locked = False
Me.Txtpcmso.Locked = False
Me.TxtLaudoVibratorio.Locked = False
Me.Txtrealizado.Locked = False


Me.txtRazao.BackColor = corEnabledTextBox
Me.txtempresa.BackColor = corEnabledTextBox
Me.TxtEst.BackColor = corEnabledTextBox
Me.Txtfuncionario.BackColor = corEnabledTextBox
Me.TxtRA.BackColor = corEnabledTextBox
Me.TxtGR.BackColor = corEnabledTextBox
Me.TxtCnpj.BackColor = corEnabledTextBox
Me.TxtCnae.BackColor = corEnabledTextBox
Me.TxtPa.BackColor = corEnabledTextBox
Me.Txtppra.BackColor = corEnabledTextBox
Me.Txtpcmso.BackColor = corEnabledTextBox
Me.TxtLaudoVibratorio.BackColor = corEnabledTextBox
Me.Txtrealizado.BackColor = corEnabledTextBox

End Sub

Private Sub DesabilitaControles()
'Me.txtCodigoFornecedor.Locked = True
Me.txtRazao.Locked = True
Me.txtempresa.Locked = True
Me.TxtEst.Locked = True
Me.Txtfuncionario.Locked = True
Me.TxtRA.Locked = True
Me.TxtGR.Locked = True
Me.TxtCnpj.Locked = True
Me.TxtCnae.Locked = True
Me.TxtPa.Locked = True
Me.Txtppra.Locked = True
Me.Txtpcmso.Locked = True
Me.TxtLaudoVibratorio.Locked = True
Me.Txtrealizado.Locked = True


Me.txtRazao.BackColor = corDisabledTextBox
Me.txtempresa.BackColor = corDisabledTextBox
Me.TxtEst.BackColor = corDisabledTextBox
Me.Txtfuncionario.BackColor = corDisabledTextBox
Me.TxtRA.BackColor = corDisabledTextBox
Me.TxtGR.BackColor = corDisabledTextBox
Me.TxtCnpj.BackColor = corDisabledTextBox
Me.TxtCnae.BackColor = corDisabledTextBox
Me.TxtPa.BackColor = corDisabledTextBox
Me.Txtppra.BackColor = corDisabledTextBox
Me.Txtpcmso.BackColor = corDisabledTextBox
Me.TxtLaudoVibratorio.BackColor = corDisabledTextBox
Me.Txtrealizado.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, colCodigo))
If .Cells(i, colCodigo).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

Reinaldo

14-10-2015 16:16:16

Desculpe companheiro, mas é praticamente impossível apenas pela leitura das rotinas descobrir/ver o erro mencionado. Existem muitas variáveis, então é preciso acompanhar
a evolução do processamento (isso e considerado depuração) e só terá efeito se tivermos seu modelo ou algo que o represente.

CJLEUTZ

14-10-2015 16:32:36

CJLEUTZ escreveu:Private Sub optAlterar_Click()
If txtCodigo.Text <> vbNullString And txtCodigo.Text <> "" Then
Call HabilitaControles
Call DesabilitaBotoesAlteracao
'dá o foco ao primeiro controle de dados
txtRazao.SetFocus......................." nao é possivel mover o foco para o controle por que esta invisivel"
Else
lblMensagem.Caption = "Não há registro a ser alterado"
End If
End Sub

Você pode me enviar o seu e-mail para eu te retornar a planilha?

Reinaldo

14-10-2015 16:38:44

Mais umavez desculpe. mas devemos manter o contato via o forum, assim outros que porventura tenham um problema similar podem se beneficiar.
Se sua planilha tiver dados confidenciais ou que não queira/pode divulgar, substitua-os por dados ficticios. Somente alguns registros, e compactea (Zip/Rar/7z...) e faça o upload no proprio forum ;apos clicar no botão responder (aqeule com letras em vermelho), abaixo da tela que se abre há um formulario com duas abas, selecione adicionar um anexo e ok

CJLEUTZ

14-10-2015 16:47:29

Segue o solicitado...Obrigado.

Reinaldo

15-10-2015 20:42:32

Em seu projeto/formulario há um Frame (frmRegistro) que está com a propriedade Enable=False; isso impede qualquer acesso aos controles/objetos dentro desse frame.

Altere a propriedade para True, que o set focus irá funcionar.

CJLEUTZ

16-10-2015 11:20:30

Professor... deu certo.

Agradeço pela sua dedicação aos usuários.

Obrigado. :D