Avatar billede bmhaj Praktikant
20. september 2014 - 10:08 Der er 22 kommentarer og
1 løsning

Modul kode

Hej,

jeg får en fejl i nedenstående kode:

'Option Compare Database
Option Explicit

Public Gbl_id As String
'her er en kommentar

Public Function get_global(i As String)
Select Case i
Case "HentId"
get_global = Gbl_id
End Select
End Function

Public Function SendPdf_Girokort()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_Udskriv_Girokort")
With rst
.MoveFirst
Do
Gbl_id = !GirokortID
DoCmd.OutputTo acOutputReport, "rpt_Girokort_Interval", acFormatPDF, Forms!frm_Udskrivningsinterval.Filplacering& !"Girokortnr. " & ![GirokortID] & ".pdf"
.MoveNext
Loop Until .EOF
.Close
End With
End Function'

Fejlen er tilsyneladende i denne linie:

DoCmd.OutputTo acOutputReport, "rpt_Girokort_Interval", acFormatPDF, Forms!frm_Udskrivningsinterval.Filplacering& !"Girokortnr. " & ![GirokortID] & ".pdf"

Resultatet af koden skal være en række pdf filer indeholdende alm. girokort oplysninger. Titlen på den enkelte fil skal være 'Girorkortnr. [GirokortID].pdf'
Avatar billede terry Ekspert
20. september 2014 - 10:14 #1
what error do you get?
Avatar billede bmhaj Praktikant
20. september 2014 - 10:52 #2
Compile error: Syntax error
Avatar billede terry Ekspert
20. september 2014 - 11:36 #3
This is whats giving the problem

Forms!frm_Udskrivningsinterval.Filplacering& !"Girokortnr. " & ![GirokortID] & ".pdf"

What I would do is have a string variable which you use to put the output file into


I'm not sue what your trying to do with the file name. I guess you have a field on the form

Forms!frm_Udskrivningsinterval.Filplacering

but whats this part.

& !"

and this part

& !



And this will give you a space in the fielname
"Girokortnr. "
Avatar billede terry Ekspert
20. september 2014 - 11:41 #4
If "Girokortnr. " is a string then you dont need a !
if GirokortID is a field in the recordset then you do need a !

so try

Forms!frm_Udskrivningsinterval.Filplacering & "Girokortnr. " & ![GirokortID] & ".pdf"
Avatar billede bmhaj Praktikant
20. september 2014 - 11:53 #5
Tried your suggestion and it might work. Got a new error:

Run-time error '2501' OutputTo-Handlingen blev annulleret
Avatar billede terry Ekspert
20. september 2014 - 12:04 #6
Have you put the file name into a variable? Much easier to see if its the correct value.

You can also put a breakpoint in the lie of code giving the problem

then when you reach the breakpoint, in the debug window (CTRL+G)

enter
?Forms!frm_Udskrivningsinterval.Filplacering & "Girokortnr. " & ![GirokortID] & ".pdf"

and see what you get. It should be the path/filename of where you are writing the file to. Is it correct?
Avatar billede terry Ekspert
20. september 2014 - 12:04 #7
You may also need to create the folder where yuou are writing files to
Avatar billede bmhaj Praktikant
20. september 2014 - 17:12 #8
Yes it looks correct. There is only 1 file where there should be 2, but the first one was correct.
Avatar billede terry Ekspert
20. september 2014 - 17:19 #9
And it is still not working ?

Any chance of seeing dB?
Avatar billede bmhaj Praktikant
20. september 2014 - 17:28 #10
Just mailed you on xxx@santhell.dk
Avatar billede bmhaj Praktikant
20. september 2014 - 17:31 #11
The error is under the Udskrivningsinterval buttom
Avatar billede terry Ekspert
20. september 2014 - 17:31 #12
have received :-)
Avatar billede terry Ekspert
20. september 2014 - 17:33 #13
Can you explain what I need to do?
Avatar billede terry Ekspert
20. september 2014 - 17:37 #14
what data do I need to enter?
Avatar billede terry Ekspert
20. september 2014 - 17:45 #15
Change code to

Public Function SendPdf_Girokort()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_Udskriv_Girokort")
With rst
.MoveFirst
Do
Gbl_id = !GirokortID
Dim sFile As String
sFile = Forms!frm_Udskrivningsinterval.Filplacering & "Girokortnr. " & ![GirokortID] & ".pdf"


DoCmd.OutputTo acOutputReport, "rpt_Girokort_Interval", acFormatPDF, sFile

.MoveNext
Loop Until .EOF
.Close
End With
End Function


Make sure the folders exist, if they don't you should create them BEFORE trying to write to folder


C:\Privat\Vor Frue IF\Rapporter
Avatar billede terry Ekspert
20. september 2014 - 17:47 #16
move Dim sFile As String
to start of code
Avatar billede terry Ekspert
20. september 2014 - 17:47 #17
.
Avatar billede bmhaj Praktikant
20. september 2014 - 20:07 #18
So far so good but, do I need to change the query as well and to what?
Avatar billede terry Ekspert
21. september 2014 - 10:16 #19
Public Function SendPdf_Girokort()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim sFile As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("tbl_Udskriv_Girokort")
With rst
.MoveFirst
Do
Gbl_id = !GirokortID

sFile = Forms!frm_Udskrivningsinterval.Filplacering & "Girokortnr. " & ![GirokortID] & ".pdf"


DoCmd.OutputTo acOutputReport, "rpt_Girokort_Interval", acFormatPDF, sFile

.MoveNext
Loop Until .EOF
.Close
End With
End Function


Change the code to this, then create the folders where you intend writing the pdf files.

Part of the file name is "Girokortnr. "

If you don't need a space at the end of this then remove it.

It should work, I have tried it.
Avatar billede bmhaj Praktikant
21. september 2014 - 11:19 #20
hmm... still get a error:

Run-time error '3085':
Der er en ikke-defineret funktion "get_global" i udtrykket
Avatar billede terry Ekspert
21. september 2014 - 11:31 #21
Can you send me the dB again, the one where you still get an error.
Avatar billede terry Ekspert
21. september 2014 - 11:32 #22
and please explain the steps you take before you get the error.
Avatar billede terry Ekspert
21. september 2014 - 12:48 #23
Thanks
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester