Printing with path name saved in a table

Asked

Viewed 270 times

8

I created a table called Funcionarios where I have at least 2 fields:

ID and caminho_impressao.

Where I put it for example:

  1. C: User Users1 Documents\
  2. C: User Users2 Documents\

Then I tried to print a PDF of a report as follows:

Dim FileNamePDF As String
Dim SetDirectoryPDF As String
Dim strRelatorio As String

    
' set directory to save to
SetDirectoryPDF = DLookup("caminho_impressao", "Funcionarios", "ID=" & login.ID)

'set the filename and save location
strRelatorio = "Relatorio_mensal"
'Tentei e não deu
'FileNamePDF = SetDirectoryPDF & strRelatorio & ".pdf"
FileNamePDF = CStr(SetDirectoryPDF) & strRelatorio & ".pdf"
MsgBox FileNamePDF
DoCmd.OutputTo acOutputReport, strRelatorio, acFormatPDF, FileNamePDF, False

But I could not generate the file. The following error message appears:

Captura de Tela

Question

How can I deal with this particular mistake?

  • A question: what is displayed in the call 'Msgbox Filenamepdf'? I ask this as the error may be due to something wrong in the output file path/name.

  • Incidentally, silly question (I know), but the path exists?

  • I actually already solved the problem, it was all right, I just needed to compress and fix the bd, so everything worked perfect.

  • 9

    Good then! How about you add an answer with your conclusions? This can help someone else in the future. :)

  • You could put the solution here for us to learn too?

1 answer

4


'Imprimir todos os relatórios

Dim FileNamePDF As String
Dim SetDirectoryPDF As String
Dim strRelatorio As String

'Tabela Funcionarios contem pelo menos os campos: ID, Nome, caminho_impressao
SetDirectoryPDF = DLookup("caminho_impressao", "Funcionarios", "ID=" & login.ID)

strRelatorio = "Orcamentos"
FileNamePDF = SetDirectoryPDF & strRelatorio & ".pdf"
DoCmd.OutputTo acOutputReport, strRelatorio, acFormatPDF, FileNamePDF, False

strRelatorio = "Vendas"
FileNamePDF = SetDirectoryPDF & strRelatorio & ".pdf"
DoCmd.OutputTo acOutputReport, strRelatorio, acFormatPDF, FileNamePDF, False

strRelatorio = "Contratos"
FileNamePDF = SetDirectoryPDF & strRelatorio & ".pdf"
DoCmd.OutputTo acOutputReport, strRelatorio, acFormatPDF, FileNamePDF, False

MsgBox "Os arquivos foram salvos na pasta Bibliotecas\Documentos.", vbInformation, ""

On way_print I define the path of each machine (employee), example,

C:\Users\vendedor01\documents\

In fact, the code was correct from before, but only corrected when I asked 'Compress and Repair...'

Browser other questions tagged

You are not signed in. Login or sign up in order to post.