Jump to content
Fórum Script Brasil
  • 0

CRYSTAL REPORT XI


Guilhermemfa

Question

Pessoal to com seguinte problema:

fiz meu relatorio no Crystal Report XI sem nenhum problema.

Porém se eu tento mudar a pasta onde está meu MDB via código aparece o seguinte erro:

"This field name is not known."

Caminho é a variavel que recebe o local+nome arquivo MDB

se eu mudo o caminho da erro, se volto para o caminho padrão da certo

alguém sabe me dizer onde tenho que alterar no codigo abaixo?

Public CnbancoPDF As ADODB.Connection

Private Sub Form_Load()
    'On Error GoTo tratar
    Dim Report1 As New CrystalReport1
    Dim Report As CRAXDRT.Report
    Dim rsRelPDF As New ADODB.Recordset
    Dim sqlRelPDF As String

    Set CnbancoPDF = New ADODB.Connection
    CnbancoPDF.Open "Provider = Microsoft.JET.OLEDB.4.0; Data Source =" & Caminho

    rsRelPDF.CursorLocation = adUseClient
    sqlRelPDF = "select * from tbtempPDF,tbitemorc,tbcontrato where tbtempPDF.numorc = tbitemorc.codorc and tbitemorc.codigo = tbcontrato.codigo"
    rsRelPDF.Open sqlRelPDF, CnbancoPDF, adOpenForwardOnly, adLockReadOnly, adCmdText
    Set rsRelPDF.ActiveConnection = Nothing

    Set Report = Report1
    Report.DiscardSavedData
    Report.Database.SetDataSource rsRelPDF

    'Report1.RecordSelectionFormula = "{tbtempPDF.codorc}= " & Form1.Text5
    CaminhoArquivo = ""
    NomeArquivo = ""
    CaminhoArquivo = Mid$(frmConfiguracao.txtCaminho, 1, Len(frmConfiguracao.txtCaminho) - Len("contrato.mdb"))
    NomeArquivo = "CONTRATO " & Form1.txtCad(2) & " - " & Form1.Text5.Text & ".pdf"
    Form2.Caption = CaminhoArquivo & NomeArquivo

    Screen.MousePointer = vbHourglass
    CRViewer1.ReportSource = Report
    CRViewer1.ViewReport
    CRViewer1.Zoom (120)
    Screen.MousePointer = vbDefault

    With Report
        .ExportOptions.DestinationType = crEDTDiskFile
        .ExportOptions.FormatType = crEFTPortableDocFormat
        .ExportOptions.DiskFileName = CaminhoArquivo & NomeArquivo
        .Export False
    End With


    rsRelPDF.Close
    CnbancoPDF.Close
    Set CnbancoPDF = Nothing
    Set rsRelPDF = Nothing
    Set Report = Nothing
    Exit Sub
tratar:
    MsgBox ERR.Description
End Sub

Private Sub Form_Resize()
    CRViewer1.Top = 0
    CRViewer1.Left = 0
    CRViewer1.Height = ScaleHeight
    CRViewer1.Width = ScaleWidth
End Sub

Edited by kuroi
Adicionar tag CODE
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Achei um codigo que altera o local do MDB, adaptei ao meu e funcionou.

O interessante é que eu não precisei montar a query.

Se alguém tiver algo a comentar ou a acrescentar ficarei grato

Private Sub Form_Load()
    On Error GoTo tratar
    Dim CRXApplication As New CRAXDDRT.Application
    Dim Report1 As New CrystalReport1

    Set CRXApplication = CreateObject("CrystalRuntime.Application.11")
    Dim CRXReport As New CRAXDDRT.Report
    Dim CRXDatabase As CRAXDDRT.Database

    Set CRXReport = Report1
    Set CRXDatabase = CRXReport.Database

    CRXDatabase.Tables(1).Location = Caminho 'essa linha resolveu meu problema<br/>
    CRViewer1.ReportSource = CRXReport
    CRViewer1.ViewReport
    
    CaminhoArquivo = ""
    NomeArquivo = ""
    CaminhoArquivo = Mid$(frmConfiguracao.txtCaminho, 1, Len(frmConfiguracao.txtCaminho) - Len("contrato.mdb"))
    NomeArquivo = "CONTRATO " & Form1.txtCad(2) & " - " & Form1.Text5.Text & ".pdf"
    Form2.Caption = CaminhoArquivo & NomeArquivo
    With CRXReport
        .ExportOptions.DestinationType = crEDTDiskFile
        .ExportOptions.FormatType = crEFTPortableDocFormat
        .ExportOptions.DiskFileName = CaminhoArquivo & NomeArquivo
        .Export False
    End With
tratar:
    MsgBox ERR.Description
End Sub

Edited by kuroi
Adicionar tag CODE
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      651.8k
×
×
  • Create New...