Notifications
Clear all

Erro 91 - variável do objeto ou a variável do bloco 'With'

2 Posts
2 Usuários
0 Reactions
1,083 Visualizações
wfranca
(@wfranca)
Posts: 297
Reputable Member
Topic starter
 

Pessoal,

no meu form de pesquisa estou definindo que a minha combobox (cboordenar) e a minha Listbox (Listbox1) sejam carregadas.

porém, agora quando inicializo o meu forme ele me da o erro 91 dizendo q minha variável não foi definida.

ele me para na linha "resume trata saída", já quebrei a cabeça e não identifiquei o erro.

---------------------------------------------------------------------------------------------------------------------------------------------------

Private Sub PopulaListBox(ByVal NomeEmpresa As String, _
ByVal NomeContato As String, _
ByVal Endereco As String, _
ByVal Telefone As String, _
ByVal Regiao As String)

On Error GoTo trataErro

Dim rst As ADODB.Recordset

Dim campo As Field

Dim myArray() As Variant
Dim I As Integer

Dim li As ListItem, fld As Field, ch As ColumnHeader
Dim Column As Long
Dim Counter As Long
Counter = 0

Set rst = PreecheRecordSet(NomeEmpresa, NomeContato, Endereco, Telefone, Regiao)

'preenche o combobox com os nomes dos campos
'persiste o índice
Dim indiceTemp As Long
indiceTemp = ListBox1.ListIndex
indiceTemp = cboordenar.ListIndex
ListBox1.Clear
cboordenar.Clear
For Each campo In rst.Fields
ListBox1.AddItem campo.Name
cboordenar.AddItem campo.Name
Next
'recupera o índice selecionado
ListBox1.ListIndex = indiceTemp
cboordenar.ListIndex = indiceTemp

'Colunas a Preencher Inicia na Primeira
For I = 0 To rst.Fields.Count - 1 'For i = 1 : a partir da 2ª coluna
Set ch = lstLista.ColumnHeaders.Add(, , rst.Fields(I).Name)
'ch.Width = 48 'Define o Tamanho de Todas as COLUNAS
'MsgBox rst.Fields(i).Name
Next

'Clear the Column Headers
lstLista.ListItems.Clear

'coloca as linhas do RecordSet num Array, se houver linhas neste
If Not rst.BOF Then
Do While Not rst.EOF

'Preenche o LISTVIEW a partir da 2ª Coluna
'Set li = lstLista.ListItems.Add(, "k" & rst.Fields(0), CheckNull(rst.Fields(1)))
'Fill in the rest of the columns
'For i = 2 To rst.Fields.Count - 1
'li.SubItems(i - 1) = CheckNull(rst.Fields(i))

'Preenche o LISTVIEW a partir da 1ª Coluna
Set li = lstLista.ListItems.Add(, "k" & rst.Fields(0), CheckNull(rst.Fields(0)))
'Fill in the rest of the columns
For I = 1 To rst.Fields.Count - 1
li.SubItems(I) = CheckNull(rst.Fields(I))
Next

rst.MoveNext 'Move to next record
Loop

'Define os Tamanhos das colunas automaticamente
Call TamanhoColAutomatico

End If
'atualiza o label de mensagens

If rst.RecordCount <= 0 Then
lblMensagens.Caption = rst.RecordCount & " registros encontrados"
Else
lblMensagens.Caption = rst.RecordCount & " registros encontrados"
End If

Exit Sub

' Fecha o conjunto de registros.
Set rst = Nothing
' Fecha a conexão.
'conn.Close

TrataSaida:
Exit Sub
trataErro:
Debug.Print Err.Description & vbNewLine & Err.Number & vbNewLine & Err.Source
MsgBox Err.Description & vbNewLine & Err.Number & vbNewLine & Err.Source
Resume TrataSaida
End Sub

Welington Gonçalves

 
Postado : 10/03/2015 10:55 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Para facilitar nos teste em localizar o erro, por favor poste seu arquivo modelo!!

Att

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 10/03/2015 1:49 pm