Link to home
Start Free TrialLog in
Avatar of Jose Bredariol
Jose BredariolFlag for Brazil

asked on

Printer Problem using Visual Basic 2008

Printer never ends, and allways print the same page.
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Do you have some code to show ?
Avatar of Jose Bredariol

ASKER

Here it is.

  Private Sub Print_printpage(ByVal sender As Object, ByVal e As PrintPageEventArgs)

        Dim MyFont As Font = New Font("Arial", 12, FontStyle.Bold)
        Dim S As String = "Relatorio CET ano base : " & Glbano
        Dim Y As Integer = e.MarginBounds.Y + 5
        Dim SSize As SizeF = e.Graphics.MeasureString(S, MyFont)
        Dim Db As New ADODB.Recordset
        Dim Cn As New ADODB.Connection
        Dim Xsql As String

        Dim CRM, OBS As String
        Dim anosba, anocreden, hospsede, cnrm, dtquitacao, Descricao As String
        Dim txtcelular As Object
        Dim txttelefone2 As Object
        Dim txttelefone1 As Object
        Dim txtfax As Object
        Dim txtemail As Object
        Dim txtestado As Object
        Dim txtcxpostal As Object
        Dim Txtcep As Object
        Dim txtbairro As Object
        Dim txtcidade As Object
        Dim txtcomplemento As Object
        Dim txtlocalidade As Object
        Dim txtmatriculamembro As Object
        Dim Txt_celular As Object
        Dim txtnome As Object
        Dim homepage As Object
        Dim email As Object
        Dim fax As Object
        Dim telefone2 As Object
        Dim telefone1 As Object
        Dim cxpostal As Object
        Dim cep As Object
        Dim estado As Object
        Dim cidade As Object
        Dim complement As Object
        Dim bairro As Object
        Dim localidade As Object
        Dim Orgao As Object
        Dim linesPerPage As Single = 0
        Dim lineHeight As Single = MyFont.GetHeight(e.Graphics)

        Dim NOME, SOCIAL, PRATICO, TEORICO, TOTAL As String

        Dim TRABALHO As String

        Dim SEDE, AFIL, ATME1, ATME2, ATME3, HANME1, HANME2, HANME3 As String

        Dim ESPEC, XDAT, ORIGEM, TITULO, Outros, CBA, NATUR, EVENTO, EVENTO2, TIPO, DATAEV, ONDE, VOLUME, PAGINA As String

        Dim ASA, TEMPO, SEXO, F_ETARIA, C_CIRURGIA, C_REALIZADAS, T_ANESTESICAs, NECROPSIA As String
        Dim C_MORTIS_P, C_MORTIS_D, C_OBITO, C_PORQUE, MES, ME1, ME2, ME3, LOCAL_O, MOMENTO As String

        Dim coord, reun, entre, durac As String
        Dim xrrv_dur, xrrv_num, xrob_dur, xrob_num, xrcp_dur, xrcp_num, reunum, reumed, outrasnum, outrastot As String

        Dim trauma_v, trauma_c, trauma_l, dentes_v, dentes_c, dentes_l As String
        Dim aspiracao_v, aspiracao_c, aspiracao_l, bronco_v, bronco_c, bronco_l As String
        Dim pneumo_v, pneumo_c, pneumo_l, edemia_v, edemia_c, edemia_l As String
        Dim outras_v, outras_c, outras_l, circula_v, circula_c, circula_l As String
        Dim fibri_v, fibri_c, fibri_l, isquemia_v, isquemia_c, isquemia_l As String
        Dim parada_v, parada_c, parada_l, outrasp_v, outrasp_c, outrasp_l As String
        Dim neuro_v, neuro_c, neuro_l, coma_v, coma_c, coma_l As String
        Dim convulsao_v, convulsao_c, convulsao_l, outrasc_v, outrasc_c, outrasc_l As String

        Dim relac_v, relac_c, relac_l, apar_v, apar_c, apar_l As String
        Dim resp_v, resp_c, resp_l, elet_v, elet_c, elet_l As String
        Dim outrase_v, outrase_c, outrase_l, Aguda_v, Aguda_c, Aguda_l As String
        Dim hiper_v, hiper_c, hiper_l, outrash_v, outrash_c, outrash_l As String
        Dim comp_v, comp_c, comp_l, evoluc As String
        Dim causas_v, causas_c, causas_l As String

        'e.Graphics.DrawString(S, MyFont, Brushes.Black, e.MarginBounds.X + CInt(0.5 * (250 - SSize.Width)), e.MarginBounds.Y + 15)

        e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
        Y += CInt(MyFont.GetHeight(e.Graphics))
        S = "SBA - SOCIEDADE BRASILEIRA DE ANESTESIOLOGIA"
        'e.Graphics.DrawString(S, MyFont, Brushes.Black, e.MarginBounds.X + CInt(0.5 * (250 - SSize.Width)), e.MarginBounds.Y + 15)
        e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
        Y += CInt(MyFont.GetHeight(e.Graphics))
        S = " Data: " & Format(Now(), "Long Date")
        'e.Graphics.DrawString(S, MyFont, Brushes.Black, e.MarginBounds.X + CInt(0.5 * (250 - SSize.Width)), e.MarginBounds.Y + 15)
        e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
        Y += CInt(MyFont.GetHeight(e.Graphics))
        S = "-------------------------------------------------------------------------------------------------------------------------------"
        e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

        'define os campos a serem impressos
        MyFont = New Font("Arial", 10)

        If CheckBox1.Checked Then
            'imprime cet
            Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;data source=" & Dirdados & "Dados.mdb;Jet oledb:database password=SBACET2002;")
            Xsql = "Select * from CET_CET,ORGAO where CET_CET.matricula = " & glbcet & " and CET_CET.id_orgao = ORGAO.id_orgao"
            Db.Open(Xsql, Cn)

            If Not Db.EOF Then

                If Not IsDBNull(Db.Fields("Descricao").Value) Then
                    Descricao = Db.Fields("Descricao").Value
                Else
                    Descricao = ""
                End If
                Orgao = Db.Fields(7).Value

                If Not IsDBNull(Db.Fields("anocreden").Value) Then
                    anocreden = Str(Db.Fields("anocreden").Value)
                Else
                    anocreden = ""
                End If

                If Not IsDBNull(Db.Fields("hospsede").Value) Then
                    hospsede = Db.Fields("hospsede").Value
                Else
                    hospsede = ""
                End If

                If Not IsDBNull(Db.Fields("cnrm").Value) Then
                    cnrm = Db.Fields("cnrm").Value
                Else : cnrm = ""
                End If

                If Not IsDBNull(Db.Fields(6).Value) Then
                    OBS = Db.Fields(6).Value
                Else
                    OBS = ""
                End If

                If Not IsDBNull(Db.Fields("localidade").Value) Then
                    localidade = Db.Fields("localidade").Value
                Else
                    localidade = ""
                End If

                If Not IsDBNull(Db.Fields("bairro").Value) Then
                    bairro = Db.Fields("bairro").Value
                Else
                    bairro = ""
                End If

                If Not IsDBNull(Db.Fields("complement").Value) Then
                    complement = Db.Fields("complement").Value
                Else
                    complement = ""
                End If

                If Not IsDBNull(Db.Fields("cidade").Value) Then
                    cidade = Db.Fields("cidade").Value
                Else
                    cidade = ""
                End If

                If Not IsDBNull(Db.Fields("estado").Value) Then
                    estado = Db.Fields("estado").Value
                Else
                    estado = ""
                End If

                If Not IsDBNull(Db.Fields("cep").Value) Then
                    cep = Db.Fields("cep").Value
                Else
                    cep = ""
                End If

                If Not IsDBNull(Db.Fields("cxpostal").Value) Then
                    cxpostal = Db.Fields("cxpostal").Value
                Else
                    cxpostal = ""
                End If

                If Not IsDBNull(Db.Fields("telefone1").Value) Then
                    telefone1 = Db.Fields("telefone1").Value
                Else
                    telefone1 = ""
                End If

                If Not IsDBNull(Db.Fields("telefone2").Value) Then
                    telefone2 = Db.Fields("telefone2").Value
                Else
                    telefone2 = ""
                End If

                If Not IsDBNull(Db.Fields("fax").Value) Then
                    fax = Db.Fields("fax").Value
                Else
                    fax = ""
                End If

                If Not IsDBNull(Db.Fields("email").Value) Then
                    email = Db.Fields("email").Value
                Else
                    email = ""
                End If

                If Not IsDBNull(Db.Fields("homepage").Value) Then
                    homepage = Db.Fields("homepage").Value
                Else
                    homepage = ""
                End If

                Db.Close()

                Xsql = "Select * from ser_anuidadecet where matriculacet = " & glbcet
                Db.Open(Xsql, Cn)

                If Not IsDBNull(Db.Fields("dt_pgto").Value) Then
                    dtquitacao = CDate(Db.Fields("dt_pgto").Value)
                Else
                    dtquitacao = ""
                End If

                If Not IsDBNull(Db.Fields("Ano_sba").Value) Then
                    anosba = Str(Db.Fields("Ano_sba").Value)
                Else
                    anosba = ""
                End If

                linesPerPage = CInt(e.MarginBounds.Height / lineHeight)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "1.0 Dados Gerais do CET"
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "-------------------------------------------------------------------------------------------------------------------------------"
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Matricula : " & glbcet.ToString & " - " + Descricao
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Ano SBA : " & anosba.ToString & " - Ano Credenciamento : " & anocreden.ToString & " - Data quitação : " & dtquitacao.ToString
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Hospital Sede : " + hospsede + " - CNRM : " + cnrm
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = localidade + " - " + complement
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = bairro + " - " + cidade + " - " + estado
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = cep + " - " + cxpostal
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Tel(s).: " + telefone1 + " - " + telefone2 + " - Fax :  " + fax
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "E-mail : " + email + " - Home-page : " + homepage
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Observacao : " + OBS
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "-------------------------------------------------------------------------------------------------------------------------------"
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.Close()

                Xsql = "select Nome,matricula,Localidade,Complement,Cidade,Bairro,CEP,Cxpostal,Estado,Email,Fax,telefone1,Telefone2,celular from Pessoa,secret2,externo where externo.id_orgao =" & Str(Orgao) & " and externo.id_pessoa=pessoa.id_pessoa and secret2.id_pessoa=pessoa.id_pessoa and externo.ativo='S'"
                Db.Open(Xsql, Cn)

                If Not Db.EOF Then

                    If IsDBNull(Db.Fields("NOME").Value) = True Then
                        txtnome = ""
                    Else
                        txtnome = Db.Fields("NOME").Value
                    End If

                    If IsDBNull(Db.Fields("CELULAR").Value) = True Then
                        Txt_celular = ""
                    Else
                        Txt_celular = Db.Fields("CELULAR").Value
                    End If

                    If IsDBNull(Db.Fields("MATRICULA").Value) = True Then
                        txtmatriculamembro = ""
                    Else
                        txtmatriculamembro = Db.Fields("MATRICULA").Value
                    End If
                    If IsDBNull(Db.Fields("localidade").Value) = True Then
                        txtlocalidade = ""
                    Else
                        txtlocalidade = Db.Fields("localidade").Value
                    End If

                    If IsDBNull(Db.Fields("complement").Value) = True Then
                        txtcomplemento = ""
                    Else
                        txtcomplemento = Db.Fields("complement").Value
                    End If

                    If IsDBNull(Db.Fields("cidade").Value) = True Then
                        txtcidade = ""
                    Else
                        txtcidade = Db.Fields("cidade").Value
                    End If

                    If IsDBNull(Db.Fields("bairro").Value) = True Then
                        txtbairro = ""
                    Else
                        txtbairro = Db.Fields("bairro").Value
                    End If

                    If IsDBNull(Db.Fields("cep").Value) = True Then
                        Txtcep = ""
                    Else
                        Txtcep = Db.Fields("cep").Value
                    End If
                    If IsDBNull(Db.Fields("cxpostal").Value) = True Then
                        txtcxpostal = ""
                    Else
                        txtcxpostal = Db.Fields("cxpostal").Value
                    End If

                    If IsDBNull(Db.Fields("estado").Value) = True Then
                        txtestado = ""
                    Else
                        txtestado = Db.Fields("estado").Value
                    End If
                    If IsDBNull(Db.Fields("email").Value) = True Then
                        txtemail = ""
                    Else
                        txtemail = Db.Fields("email").Value
                    End If

                    If IsDBNull(Db.Fields("fax").Value) = True Then
                        txtfax = ""
                    Else
                        txtfax = Db.Fields("fax").Value
                    End If

                    If IsDBNull(Db.Fields("telefone1").Value) = True Then
                        txttelefone1 = ""
                    Else
                        txttelefone1 = Db.Fields("telefone1").Value
                    End If

                    If IsDBNull(Db.Fields("telefone2").Value) = True Then
                        txttelefone2 = ""
                    Else
                        txttelefone2 = Db.Fields("telefone2").Value
                    End If

                End If
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Responsável"
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Matricula : " & txtmatriculamembro.ToString & " - " + txtnome
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = txtlocalidade + " - " + txtcomplemento
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = txtbairro + " - " + txtcidade + " - " + txtestado
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = Txtcep + " - " + txtcxpostal
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Tel(s).: " + txttelefone1 + " - " + txttelefone2 + " - Fax :  " + txtfax
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "E-mail : " + txtemail + " - Celular : " + txtcelular
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "-------------------------------------------------------------------------------------------------------------------------------"
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.Close()

                Xsql = "Select * from cet_hosp where matricula = " & glbcet
                Db.Open(Xsql, Cn)

                If Not Db.EOF Then
                    Y += CInt(MyFont.GetHeight(e.Graphics))
                    S = "Hospitais Afiliados "
                    e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                    Do While Not Db.EOF
                        Y += CInt(MyFont.GetHeight(e.Graphics))
                        S = Db.Fields("NOME").Value + " - CNRM : " + Db.Fields("cnrm").Value
                        e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                        Db.MoveNext()
                    Loop
                    Y += CInt(MyFont.GetHeight(e.Graphics))
                    S = "-------------------------------------------------------------------------------------------------------------------------------"
                    e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                End If

            End If
            Db.Close()

            Do Until Y >= 1050
                e.Graphics.DrawString(" ", MyFont, Brushes.Black, 5, Y)
                Y += 14
            Loop

            e.HasMorePages = True
            e.Graphics.DrawString("Continuação ", MyFont, Brushes.Black, 5, Y)


        'IMPRIME CONCEITO
        If CheckBox2.Checked Then
            Xsql = "SELECT * from cet_conceitome "
            Db.Open(Xsql, Cn)

            S = "Conceituação " + Str(Glbano)
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            S = "-------------------------------------------------------------------------------------------------------------------------------"
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Y += CInt(MyFont.GetHeight(e.Graphics))

            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    NOME = Db.Fields("NOME").Value
                Else
                    NOME = ""
                End If
                If Not IsDBNull(Db.Fields("teorico").Value) Then
                    TEORICO = Format(Db.Fields("teorico").Value, "00")
                Else
                    TEORICO = "00"
                End If
                If Not IsDBNull(Db.Fields("SOCIAL").Value) Then
                    SOCIAL = Format(Db.Fields("SOCIAL").Value, "00")
                Else
                    SOCIAL = "00"
                End If
                If Not IsDBNull(Db.Fields("PRATICO").Value) Then
                    PRATICO = Format(Db.Fields("PRATICO").Value, "00")
                Else
                    PRATICO = "00"
                End If
                If Not IsDBNull(Db.Fields("TOTAL").Value) Then
                    TOTAL = Format(Db.Fields("TOTAL").Value, "00")
                Else
                    TOTAL = "0"
                End If

                S = Str(Db.Fields("MATRICULA").Value) + " - " + NOME
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "Social : " + SOCIAL + "   Prático : " + PRATICO + "   Teórico : " + TEORICO + "    Total : " + TOTAL
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))

                Db.MoveNext()
            Loop
            Y += CInt(MyFont.GetHeight(e.Graphics))
            S = "-------------------------------------------------------------------------------------------------------------------------------"
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Db.Close()

        End If

        'TRABALHO
        If CheckBox3.Checked Then
            Xsql = "SELECT * from cet_trabalhome "
            Db.Open(Xsql, Cn)

            S = "Trabalhos ME 3 " + Str(Glbano)
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            S = "-------------------------------------------------------------------------------------------------------------------------------"
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Y += CInt(MyFont.GetHeight(e.Graphics))

            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    NOME = Db.Fields("NOME").Value
                Else
                    NOME = ""
                End If
                If Not IsDBNull(Db.Fields("trabalho").Value) Then
                    TRABALHO = Format(Db.Fields("trabalho").Value, "00")
                Else
                    TRABALHO = ""
                End If

                S = "Nome : " + NOME
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                S = "     Trabalho : " + TRABALHO
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                Db.MoveNext()
            Loop
            Y += CInt(MyFont.GetHeight(e.Graphics))
            S = "-------------------------------------------------------------------------------------------------------------------------------"
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Db.Close()

        End If

        'ATIVIDADES ME
        If CheckBox4.Checked Then

            Xsql = "SELECT * from cet_relat where matricula=" + glbcet + " And ANO_CET=" + Str$(Glbano)
            Db.Open(Xsql, Cn)

            S = ("Atividades Práticas com efetiva participação de ME" + Str(Glbano))
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            S = ("------------------------------------------------------- " + Str(Glbano))
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            Do While Not Db.EOF

                If Not IsDBNull(Db.Fields("HOSP_SEDEME").Value) Then
                    SEDE = Str$(Db.Fields("HOSP_SEDEME").Value)
                Else
                    SEDE = "0"
                End If
                If Not IsDBNull(Db.Fields("HOSP_AFILIME").Value) Then
                    AFIL = Str$(Db.Fields("HOSP_AFILIME").Value)
                Else
                    AFIL = "0"
                End If
                If Not IsDBNull(Db.Fields("ATOS_AME1ME").Value) Then
                    ATME1 = Format(Db.Fields("ATOS_AME1ME").Value, "0000")
                Else
                    ATME1 = "0"
                End If
                If Not IsDBNull(Db.Fields("ATOS_AME2ME").Value) Then
                    ATME2 = Format(Db.Fields("ATOS_AME2ME").Value, "0000")
                Else
                    ATME2 = "0"
                End If
                If Not IsDBNull(Db.Fields("H_ANESTESIAME1ME").Value) Then
                    HANME1 = Format(Db.Fields("H_ANESTESIAME1ME").Value, "0000")
                Else
                    HANME1 = "0"
                End If
                If Not IsDBNull(Db.Fields("H_ANESTESIAME2ME").Value) Then
                    HANME2 = Format(Db.Fields("H_ANESTESIAME2ME").Value, "0000")
                Else
                    HANME2 = "0"
                End If
                If Not IsDBNull(Db.Fields("ATOS_AME3ME").Value) Then
                    ATME3 = Format(Db.Fields("ATOS_AME3ME").Value, "0000")
                Else
                    ATME3 = "0"
                End If
                If Not IsDBNull(Db.Fields("H_ANESTESIAME3ME").Value) Then
                    HANME3 = Format(Db.Fields("H_ANESTESIAME3ME").Value, "0000")
                Else
                    HANME3 = "0"
                End If

                S = "Hospital Sede : " + SEDE + "   -   Afiliado(s) : " + AFIL
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Atos ME1  : " + ATME1 + "   -  Atos ME2   : " + ATME2 + "   -  Atos ME3   : " + ATME3
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Horas ME1 : " + HANME1 + "   -   Horas ME2 : " + HANME2 + "   -   Horas ME3 : " + HANME3
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.MoveNext()
            Loop

            Db.Close()

            Xsql = "Select * from cet_tothosp where matricula = " + glbcet + " and ANO_CET=" + Str$(Glbano)
            Db.Open(Xsql, Cn)
            If Not Db.EOF Then
                S = "Hospitais Afiliados " + Str(Glbano)
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Do While Not Db.EOF
                    If Not IsDBNull(Db.Fields("TOTANESTESIAME").Value) Then
                        S = Db.Fields("NOME").Value + " - Total : " + Db.Fields("TOTANESTESIAME").Value.ToString
                        Y += CInt(MyFont.GetHeight(e.Graphics))
                        e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                    End If
                    Db.MoveNext()
                Loop

            End If

            Y += CInt(MyFont.GetHeight(e.Graphics))
            S = "-------------------------------------------------------------------------------------------------------------------------------"
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
            Db.Close()
        End If

        ' ANEXO 1 ATIVIDADES DIDATICAS
        If CheckBox5.Checked Then

            Xsql = "SELECT * from cet_TEMAS,SECRET2,PESSOA where SECRET2.ID_PESSOA=PESSOA.ID_PESSOA AND SECRET2.MATRICULA=CET_TEMAS.MATRICULAMEMBRO AND CET_TEMAS.matricula=" + glbcet + " and ano_cet=" + Str(Glbano)
            Db.Open(Xsql, Cn)

            S = "Anexo 1 - Temas Livres " + Str(Glbano)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            S = "---------------------------------------- "
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)


            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    NOME = Db.Fields("NOME").Value
                Else
                    NOME = ""
                End If
                If Not IsDBNull(Db.Fields("Outros").Value) Then
                    Outros = Db.Fields("Outros").Value
                Else
                    Outros = ""
                End If
                If Not IsDBNull(Db.Fields("CBA").Value) Then
                    CBA = Db.Fields("CBA").Value
                Else
                    CBA = ""
                End If

                S = "Nome : " + NOME + " -  CBA : " + CBA
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                S = "Título " + Outros
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = " "
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.MoveNext()

            Loop
            Db.Close()

            Xsql = "SELECT * from cet_PART,SECRET2,PESSOA where SECRET2.ID_PESSOA=PESSOA.ID_PESSOA AND SECRET2.MATRICULA=CET_PART.MATRICULAMEMBRO AND CET_PART.matricula=" + glbcet + " and ano_cet=" + Str(Glbano)
            Db.Open(Xsql, Cn)

            S = "Anexo 1 - Participações " + Str(Glbano)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            S = "----------------------------------------- "
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    NOME = Db.Fields("NOME").Value
                Else
                    NOME = ""
                End If
                If Not IsDBNull(Db.Fields("NATUREZA").Value) Then
                    NATUR = Db.Fields("NATUREZA").Value
                Else
                    NATUR = ""
                End If
                If Not IsDBNull(Db.Fields("EVENTO").Value) Then
                    EVENTO = Db.Fields("EVENTO").Value
                Else
                    EVENTO = ""
                End If
                If Not IsDBNull(Db.Fields("EVENTO2").Value) Then
                    EVENTO2 = Db.Fields("EVENTO2").Value
                Else
                    EVENTO2 = ""
                End If
                If Not IsDBNull(Db.Fields("Data").Value) Then
                    DATAEV = Format(Db.Fields("Data").Value, "dd/mm/yyyy")
                Else
                    DATAEV = ""
                End If
                If Not IsDBNull(Db.Fields("TIPO").Value) Then
                    TIPO = Db.Fields("TIPO").Value
                Else
                    TIPO = ""
                End If

                S = "Nome : " + NOME + " -  Data : " + DATAEV
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                S = "Natureza " + NATUR + "  -  " + EVENTO
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                S = "Apresentaçao : " + TIPO
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)
                S = "Tema : " + EVENTO2
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.MoveNext()

            Loop

            Db.Close()

            Xsql = "SELECT * from cet_trabpub,SECRET2,PESSOA where SECRET2.ID_PESSOA=PESSOA.ID_PESSOA AND SECRET2.MATRICULA=CET_trabpub.MATRICULAMEMBRO AND CET_trabpub.matricula=" + glbcet + " and ano_cet=" + Str(Glbano)
            Db.Open(Xsql, Cn)

            S = "Anexo 1 - Trabalhos RBA e Outros Periódicos" + Str(Glbano)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            S = "------------------------------------------------ "
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    NOME = Db.Fields("NOME").Value
                Else
                    NOME = ""
                End If
                If Not IsDBNull(Db.Fields("ONDE").Value) Then
                    ONDE = Db.Fields("ONDE").Value
                Else
                    ONDE = ""
                End If
                If Not IsDBNull(Db.Fields("TITULO").Value) Then
                    Outros = Db.Fields("TITULO").Value
                Else
                    Outros = ""
                End If
                If Not IsDBNull(Db.Fields("VOLUME").Value) Then
                    VOLUME = Db.Fields("VOLUME").Value
                Else
                    VOLUME = ""
                End If
                If Not IsDBNull(Db.Fields("PAGINA").Value) Then
                    PAGINA = Db.Fields("PAGINA").Value
                Else
                    PAGINA = ""
                End If

                S = "Nome : " + NOME
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Titulo : " + Outros
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Períodico " + ONDE + " -  Volume : " + VOLUME + "  - Página(s) : " + PAGINA
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = " "
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.MoveNext()

            Loop

            Db.Close()

            Xsql = "SELECT * from cet_traboutras,SECRET2,PESSOA where SECRET2.ID_PESSOA=PESSOA.ID_PESSOA AND SECRET2.MATRICULA=CET_traboutras.MATRICULAMEMBRO AND CET_traboutras.matricula=" + glbcet + " and ano_cet=" + Str(Glbano)
            Db.Open(Xsql, Cn)

            S = "Anexo 1 - Trabalhos Publ. Periódicos AMB" + Str(Glbano)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            S = "------------------------------------------------ "
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("TITULO").Value) Then
                    TITULO = Db.Fields("TITULO").Value
                Else
                    TITULO = ""
                End If
                If Not IsDBNull(Db.Fields("ONDE").Value) Then
                    ONDE = Db.Fields("ONDE").Value
                Else
                    ONDE = ""
                End If
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    Outros = Db.Fields("NOME").Value
                Else
                    Outros = ""
                End If
                If Not IsDBNull(Db.Fields("VOLUME").Value) Then
                    VOLUME = Db.Fields("VOLUME").Value
                Else
                    VOLUME = ""
                End If
                If Not IsDBNull(Db.Fields("PAGINA").Value) Then
                    PAGINA = Db.Fields("PAGINA").Value
                Else
                    PAGINA = ""
                End If

                S = "Nome : " + Outros
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Titulo : " + TITULO
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Períodico " + ONDE + " -  Volume : " + VOLUME + "  - Página(s) : " + PAGINA
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = " "
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.MoveNext()

            Loop

            Db.Close()

            Xsql = "SELECT * from cet_public,SECRET2,PESSOA where SECRET2.ID_PESSOA=PESSOA.ID_PESSOA AND SECRET2.MATRICULA=CET_public.MATRICULAMEMBRO AND CET_public.matricula=" + glbcet + " and ano_cet=" + Str(Glbano)
            Db.Open(Xsql, Cn)

            S = "Anexo 1 - Trabalhos Publ. em Livros" + Str(Glbano)
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            S = "------------------------------------------------ "
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            Do While Not Db.EOF
                If Not IsDBNull(Db.Fields("NOME").Value) Then
                    NOME = Db.Fields("NOME").Value
                Else
                    NOME = ""
                End If
                If Not IsDBNull(Db.Fields("ESPECIALIDADE").Value) Then
                    ESPEC = Db.Fields("ESPECIALIDADE").Value
                Else
                    ESPEC = ""
                End If
                If Not IsDBNull(Db.Fields("Data").Value) Then
                    XDAT = Format(Db.Fields("Data").Value, "dd /mm / yyyy")
                Else
                    XDAT = ""
                End If
                If Not IsDBNull(Db.Fields("ORIGEM").Value) Then
                    ORIGEM = Db.Fields("ORIGEM").Value
                Else
                    ORIGEM = ""
                End If
                If Not IsDBNull(Db.Fields("TITULO").Value) Then
                    TITULO = Db.Fields("TITULO").Value
                Else
                    TITULO = ""
                End If
                If Not IsDBNull(Db.Fields("PUBLICACAO").Value) Then
                    'public = Db.Fields("publicacao
                Else
                    'public = ""
                End If

                S = "Nome : " + NOME
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Especialidade : " + ESPEC + "  - Data : " + XDAT + " (" + ORIGEM + ")"
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = "Titulo : " + TITULO
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                S = " "
                Y += CInt(MyFont.GetHeight(e.Graphics))
                e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

                Db.MoveNext()

            Loop

            S = "--------------------------------------------------------------------------------------------------------------"
            Y += CInt(MyFont.GetHeight(e.Graphics))
            e.Graphics.DrawString(S, MyFont, Brushes.Black, 5, Y)

            Db.Close()

        End If

    '    MORE CODE HAS BEEN CUT
    '    MORE CODE HAS BEEN CUT
    '    MORE CODE HAS BEEN CUT
    '    MORE CODE HAS BEEN CUT
    '    MORE CODE HAS BEEN CUT
    '    MORE CODE HAS BEEN CUT

        Me.Close()
        Me.Dispose()

    End Sub

    '    ' Prepare and show data
    '    Me.Visible = False
    '    PrintPreview.Document = PreparePrintDocument()
    '    PrintPreview.WindowState = FormWindowState.Normal
    '    PrintPreview.ShowDialog()
    '    Me.Visible = True

    'End Sub

    ''' <summary>
    ''' Print out data
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        ' Prepare data and print
        Me.Visible = False
        PrintDialog.Document = PreparePrintDocument()
        If PrintDialog.ShowDialog() = Windows.Forms.DialogResult.OK Then PrintDialog.Document.Print()
        Me.Visible = True

    End Sub

    ''' <summary>
    ''' Create print document
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Private Function PreparePrintDocument() As PrintDocument

        Dim MyPrintDocument As New PrintDocument
        MyHeaderDone = False

        AddHandler MyPrintDocument.PrintPage, AddressOf Print_PrintPage

        Return MyPrintDocument

    End Function
Humm, two questions:
1st - You are creating you own reports why ? Why don't you use Reporting Services or Crystal Reports ? It's soo much easy that way.
2nd . Português ou Brasileiro ? :)
Brasileiro. I don't know how to use Report Services. Any Tutorial ?
What version of VB.NET do you have (2003/2005/2008 ? Is it a Express version ?
I use Visual Studio 2008 Prof. Edition
Ok, I'm using Microsoft Report, but I'm receiving this error : "Subreport could not be show"

Here is the code :
''TODO: This line of code loads data into the 'DadosDataSet.ConsultaCET' table. You can move, or remove it, as needed.
form load ....
        Me.ConsultaCETTableAdapter.Fill(Me.DadosDataSet.ConsultaCET)

        Me.consintTableAdapter.Fill(Me.DadosDataSet.consint)

        Me.ReportViewer1.RefreshReport()
End Sub
I didn't saw the reply :(
Subreport could not be show
What have you in the report right now ? You have to explain what you have done.
I first creat one report using microsoft reporting. Inside this report I creat one subreport. After that I creat one form and include one microsoft reportviewer using the report i had created. When I run the application I received the following error : " Error The subreport could not be shown" This error appears in the subreport area of the report, the report area is showed correctly.
The form load code is :  
'TODO: This line of code loads data into the 'DadosDataSet.ConsultaCET' table. You can move, or remove it, as needed.
        Me.ConsultaCETTableAdapter.Fill(Me.DadosDataSet.ConsultaCET)
        'TODO: This line of code loads data into the 'DadosDataSet.consint' table. You can move, or remove it, as needed.
        Me.consintTableAdapter.Fill(Me.DadosDataSet.consint)

        Me.ReportViewer1.RefreshReport()

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the help