ERRO COM BANCO DE DADOS VAZIO
Amigos, no Form_Activate eu coloquei um função mostrarvalores até ai tudo bem .. o problema é quando o banco de dados está vazio ..ele dá o erro 3021 no mostrarvalores
como faço para solucionar esse problema ..???
Public Sub mostrarvalores()
limpar
If IsNull(Sinistro("Beneficiario1")) Then
TxtBene.Text = ""
Else
TxtBene.Text = Sinistro("Beneficiario1")
End If
If IsNull(Sinistro("Beneficiario2")) Then
TxtBene2.Text = ""
Else
TxtBene2.Text = Sinistro("Beneficiario2")
End If
If IsNull(Sinistro("Beneficiario3")) Then
TxtBene3.Text = ""
Else
TxtBene3.Text = Sinistro("Beneficiario3")
End If
If IsNull(Sinistro("Beneficiario4")) Then
TxtBene4.Text = ""
Else
TxtBene4.Text = Sinistro("Beneficiario4")
End If
If IsNull(Sinistro("Beneficiario5")) Then
TxtBene5.Text = ""
Else
TxtBene5.Text = Sinistro("Beneficiario5")
End If
If IsNull(Sinistro("Beneficiario6")) Then
TxtBene6.Text = ""
Else
TxtBene6.Text = Sinistro("Beneficiario6")
End If
Txtindenizado.Text = Format(Sinistro("Indenizado1"), "###,##0.00")
Txtindenizado2.Text = Format(Sinistro("Indenizado2"), "###,##0.00")
Txtindenizado3.Text = Format(Sinistro("Indenizado3"), "###,##0.00")
Txtindenizado4.Text = Format(Sinistro("Indenizado4"), "###,##0.00")
Txtindenizado5.Text = Format(Sinistro("Indenizado5"), "###,##0.00")
Txtindenizado6.Text = Format(Sinistro("Indenizado6"), "###,##0.00")
If IsNull(Sinistro("Data Pagamento1")) Then
Txtdtindenizacao.Text = ""
Else
Txtdtindenizacao.Text = Sinistro("Data Pagamento1")
End If
If IsNull(Sinistro("Data Pagamento2")) Then
Txtdtindenizacao2.Text = ""
Else
Txtdtindenizacao2.Text = Sinistro("Data Pagamento2")
End If
If IsNull(Sinistro("Data Pagamento3")) Then
Txtdtindenizacao3.Text = ""
Else
Txtdtindenizacao3.Text = Sinistro("Data Pagamento3")
End If
If IsNull(Sinistro("Data Pagamento4")) Then
Txtdtindenizacao4.Text = ""
Else
Txtdtindenizacao4.Text = Sinistro("Data Pagamento4")
End If
If IsNull(Sinistro("Data Pagamento5")) Then
Txtdtindenizacao5.Text = ""
Else
Txtdtindenizacao5.Text = Sinistro("Data Pagamento5")
End If
If IsNull(Sinistro("Data Pagamento6")) Then
Txtdtindenizacao6.Text = ""
Else
Txtdtindenizacao6.Text = Sinistro("Data Pagamento6")
End If
If IsNull(Sinistro("Apolice")) Then
Txtapolice2.Text = ""
Else
Txtapolice2.Text = Sinistro("Apolice")
End If
If IsNull(Sinistro("Certificado")) Then
Txtcertificado.Text = ""
Else
Txtcertificado.Text = Sinistro("Certificado")
End If
If IsNull(Sinistro("Segurado")) Then
Txtsegurado.Text = ""
Else
Txtsegurado.Text = Sinistro("Segurado")
End If
If IsNull(Sinistro("Causa")) Then
Txtcausa.Text = ""
Else
Txtcausa.Text = Sinistro("Causa")
End If
Txtvalor.Text = Format(Sinistro("Valor"), "###,##0.00")
Txtvalorindenizado.Text = Format(Sinistro("Valor Indenizado"), "###,##0.00")
If IsNull(Sinistro("Data Aviso")) Then
Txtdtaviso.Text = ""
Else
Txtdtaviso.Text = Sinistro("Data Aviso")
End If
If IsNull(Sinistro("Data Pagamento")) Then
Txtdtpagamento.Text = ""
Else
Txtdtpagamento.Text = Sinistro("Data Pagamento")
End If
On Error GoTo erro
If IsNull(cadastro("Apolice")) Then
Txtapolice.Text = ""
Else
Txtapolice.Text = cadastro("Apolice")
End If
erro:
If Err = 3021 Then
MsgBox "Estipulante Não Existe ou Não Está Cadastrado..! ", vbCritical, "Cadastro de Sinistro"
MsgBox "Voce deve Excluir esse Registro e Cadastrar um Novo..! ", vbCritical, "Cadastro de Sinistro"
CmdExcluir_Click
Else
End If
If IsNull(cadastro("Estipulantes")) Then
Txtestipulante.Text = ""
Else
Txtestipulante.Text = cadastro("Estipulantes")
End If
If IsNull(cadastro("Vigencia")) Then
Txtvigencia.Text = ""
Else
Txtvigencia.Text = cadastro("Vigencia")
End If
If IsNull(cadastro("Corretor")) Then
Txtcorretor.Text = ""
Else
Txtcorretor.Text = cadastro("Corretor")
End If
If IsNull(Sinistro("Codigo")) Then
Text1.Text = ""
Else
Text1.Text = Sinistro("Codigo")
End If
If Txtapolice.Text <> "" Then
Data3.RecordSource = "Select * from Sinistro where Apolice= '" & Txtapolice.Text & " ' "
Data3.Refresh
End If
If Text1.Text <> "" Then
Data1.RecordSource = "Select * from Historico where codigo=" & Text1.Text
Data1.Refresh
End If
End Sub
como faço para solucionar esse problema ..???
Public Sub mostrarvalores()
limpar
If IsNull(Sinistro("Beneficiario1")) Then
TxtBene.Text = ""
Else
TxtBene.Text = Sinistro("Beneficiario1")
End If
If IsNull(Sinistro("Beneficiario2")) Then
TxtBene2.Text = ""
Else
TxtBene2.Text = Sinistro("Beneficiario2")
End If
If IsNull(Sinistro("Beneficiario3")) Then
TxtBene3.Text = ""
Else
TxtBene3.Text = Sinistro("Beneficiario3")
End If
If IsNull(Sinistro("Beneficiario4")) Then
TxtBene4.Text = ""
Else
TxtBene4.Text = Sinistro("Beneficiario4")
End If
If IsNull(Sinistro("Beneficiario5")) Then
TxtBene5.Text = ""
Else
TxtBene5.Text = Sinistro("Beneficiario5")
End If
If IsNull(Sinistro("Beneficiario6")) Then
TxtBene6.Text = ""
Else
TxtBene6.Text = Sinistro("Beneficiario6")
End If
Txtindenizado.Text = Format(Sinistro("Indenizado1"), "###,##0.00")
Txtindenizado2.Text = Format(Sinistro("Indenizado2"), "###,##0.00")
Txtindenizado3.Text = Format(Sinistro("Indenizado3"), "###,##0.00")
Txtindenizado4.Text = Format(Sinistro("Indenizado4"), "###,##0.00")
Txtindenizado5.Text = Format(Sinistro("Indenizado5"), "###,##0.00")
Txtindenizado6.Text = Format(Sinistro("Indenizado6"), "###,##0.00")
If IsNull(Sinistro("Data Pagamento1")) Then
Txtdtindenizacao.Text = ""
Else
Txtdtindenizacao.Text = Sinistro("Data Pagamento1")
End If
If IsNull(Sinistro("Data Pagamento2")) Then
Txtdtindenizacao2.Text = ""
Else
Txtdtindenizacao2.Text = Sinistro("Data Pagamento2")
End If
If IsNull(Sinistro("Data Pagamento3")) Then
Txtdtindenizacao3.Text = ""
Else
Txtdtindenizacao3.Text = Sinistro("Data Pagamento3")
End If
If IsNull(Sinistro("Data Pagamento4")) Then
Txtdtindenizacao4.Text = ""
Else
Txtdtindenizacao4.Text = Sinistro("Data Pagamento4")
End If
If IsNull(Sinistro("Data Pagamento5")) Then
Txtdtindenizacao5.Text = ""
Else
Txtdtindenizacao5.Text = Sinistro("Data Pagamento5")
End If
If IsNull(Sinistro("Data Pagamento6")) Then
Txtdtindenizacao6.Text = ""
Else
Txtdtindenizacao6.Text = Sinistro("Data Pagamento6")
End If
If IsNull(Sinistro("Apolice")) Then
Txtapolice2.Text = ""
Else
Txtapolice2.Text = Sinistro("Apolice")
End If
If IsNull(Sinistro("Certificado")) Then
Txtcertificado.Text = ""
Else
Txtcertificado.Text = Sinistro("Certificado")
End If
If IsNull(Sinistro("Segurado")) Then
Txtsegurado.Text = ""
Else
Txtsegurado.Text = Sinistro("Segurado")
End If
If IsNull(Sinistro("Causa")) Then
Txtcausa.Text = ""
Else
Txtcausa.Text = Sinistro("Causa")
End If
Txtvalor.Text = Format(Sinistro("Valor"), "###,##0.00")
Txtvalorindenizado.Text = Format(Sinistro("Valor Indenizado"), "###,##0.00")
If IsNull(Sinistro("Data Aviso")) Then
Txtdtaviso.Text = ""
Else
Txtdtaviso.Text = Sinistro("Data Aviso")
End If
If IsNull(Sinistro("Data Pagamento")) Then
Txtdtpagamento.Text = ""
Else
Txtdtpagamento.Text = Sinistro("Data Pagamento")
End If
On Error GoTo erro
If IsNull(cadastro("Apolice")) Then
Txtapolice.Text = ""
Else
Txtapolice.Text = cadastro("Apolice")
End If
erro:
If Err = 3021 Then
MsgBox "Estipulante Não Existe ou Não Está Cadastrado..! ", vbCritical, "Cadastro de Sinistro"
MsgBox "Voce deve Excluir esse Registro e Cadastrar um Novo..! ", vbCritical, "Cadastro de Sinistro"
CmdExcluir_Click
Else
End If
If IsNull(cadastro("Estipulantes")) Then
Txtestipulante.Text = ""
Else
Txtestipulante.Text = cadastro("Estipulantes")
End If
If IsNull(cadastro("Vigencia")) Then
Txtvigencia.Text = ""
Else
Txtvigencia.Text = cadastro("Vigencia")
End If
If IsNull(cadastro("Corretor")) Then
Txtcorretor.Text = ""
Else
Txtcorretor.Text = cadastro("Corretor")
End If
If IsNull(Sinistro("Codigo")) Then
Text1.Text = ""
Else
Text1.Text = Sinistro("Codigo")
End If
If Txtapolice.Text <> "" Then
Data3.RecordSource = "Select * from Sinistro where Apolice= '" & Txtapolice.Text & " ' "
Data3.Refresh
End If
If Text1.Text <> "" Then
Data1.RecordSource = "Select * from Historico where codigo=" & Text1.Text
Data1.Refresh
End If
End Sub
Especifique melhor,qual linha exatemente ocorre o erro?
Suponho que, quando activa o forms, carrega a sua recordset com os registos vindos de uma determinada tabela e, logo, mostra os mesmos no forms. A sua recordset chama-se "Sinistro", julgo. Certo?
Bom, então nesse mesmo local, precisa colocar algo do género:
If IsNull(Sinistro.Fields(0)) Then
MsgBox "Não existem registos"
Exit sub
Else
mostravalores
End If
Bom, então nesse mesmo local, precisa colocar algo do género:
If IsNull(Sinistro.Fields(0)) Then
MsgBox "Não existem registos"
Exit sub
Else
mostravalores
End If
nessa linha
If IsNull(Sinistro("Beneficiario1")) Then
TxtBene.Text = ""
Else
TxtBene.Text = Sinistro("Beneficiario1")
End If
If IsNull(Sinistro("Beneficiario1")) Then
TxtBene.Text = ""
Else
TxtBene.Text = Sinistro("Beneficiario1")
End If
voc~e não colocou a condição de IsNull para esses :
Txtindenizado.Text = Format(Sinistro("Indenizado1"), "###,##0.00")
Txtindenizado2.Text = Format(Sinistro("Indenizado2"), "###,##0.00")
Txtindenizado3.Text = Format(Sinistro("Indenizado3"), "###,##0.00")
Txtindenizado4.Text = Format(Sinistro("Indenizado4"), "###,##0.00")
Txtindenizado5.Text = Format(Sinistro("Indenizado5"), "###,##0.00")
Txtindenizado6.Text = Format(Sinistro("Indenizado6"), "###,##0.00")
você ja tentou executar o código passo a passo ( F8 ) ? Para ver em qual linha está o erro ?
Por Isso é interressnate até numerar as linhas e no tratamento de erro capturar a número da linha que gerou o erro.
Txtindenizado.Text = Format(Sinistro("Indenizado1"), "###,##0.00")
Txtindenizado2.Text = Format(Sinistro("Indenizado2"), "###,##0.00")
Txtindenizado3.Text = Format(Sinistro("Indenizado3"), "###,##0.00")
Txtindenizado4.Text = Format(Sinistro("Indenizado4"), "###,##0.00")
Txtindenizado5.Text = Format(Sinistro("Indenizado5"), "###,##0.00")
Txtindenizado6.Text = Format(Sinistro("Indenizado6"), "###,##0.00")
você ja tentou executar o código passo a passo ( F8 ) ? Para ver em qual linha está o erro ?
Por Isso é interressnate até numerar as linhas e no tratamento de erro capturar a número da linha que gerou o erro.
Tópico encerrado , respostas não são mais permitidas