DoCmd.OutputTo acOutputRepor runtime error Help

Gand114

Registered User.
Local time
Today, 18:01
Joined
Apr 21, 2016
Messages
15
Hi everybody,
hope you guys can help me.
I am a total newbe with VBA so please be good to me :)

My issue is:
I have a db where I ve stored all the prices for my customers in one single table
I create the rate sheet for every single customer pulling the data with a query into a report.

The query parameters are basically customer name and expiration date.
When i pull the report for one single customer I use a form to input these 2.

Every time I had to create all of the ratesheet for each customer (so far around 100 different ratesheets at the end of each month) it was a nightmare; so with extreme difficulties i managed to create the following that should create all the reports at once

Code:
Private Sub Comando0_Click()

Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim rs As New ADODB.Recordset
rs.activeconnection = cnn1
rs.Open "[soloragsoc]"

Dim ragsoc As String
Dim file As String
Dim path As String
Dim db As Database
Dim ingragsoc As String
Dim repName As String
repName = "new report"



If Not rs.EOF Then
rs.MoveFirst
Do While Not rs.EOF
ingragsoc = rs.Fields(0)
path = "C:\Users\diego\Desktop\EXEPE"
file = "\Listino export Maggio 2016" & " " & ingragsoc & ".pdf"
Dim fulpafi As String
fulpafi = path & file


DoCmd.OpenReport repName, acViewPreview, , "[Q_Retrieve nolo export]![ragione sociale] ='" & ingragsoc & "'", , acFormatPDF, fulpafi
DoCmd.Close acReport, repName

rs.MoveNext

Loop
End If
rs.Close
Set rs = Nothing
Set db = Nothing

End Sub

It kind of works but it does not create all of the ratesheet and I get at a certain point a "run-time error '2501' the outputto action was canceled"

in the end out of 100 report i get 81 (it's always 81 it seems) wich is way better than nothing but still...

Can you help me?
 
I would check the 82nd. I'd suspect either there's no data for that one, or something in ingragsoc causes an invalid file name error.

I think you may have had a copy/paste incident, as that code doesn't look valid.
 
Dear Paul,
tnx a lot.
I had eventually found sometime to look into it and indeed apparently are Always the same "Customer names" that produce the issue.
I cannot figure out why though, any idea of what would be "dislikeable" to access?

Meanwhile I ve check the code, i might have actually made a mess with copy paste, but since i cannot figure out where it went bad, I' copy it once more.

Code:
 Private Sub Comando0_Click()
 Dim cnn1 As ADODB.Connection
Set cnn1 = CurrentProject.Connection
Dim rs As New ADODB.Recordset
rs.activeconnection = cnn1
rs.Open "[soloragsoc]"
 Dim ragsoc As String
Dim pafi As String
Dim file As String
Dim path As String
Dim db As Database
Dim ingragsoc As String
Dim repName As String
repName = "new report"
ragsoc = "[Q_Retrieve nolo export]![ragione sociale]"
 pafi = path & file
 If Not rs.EOF Then
rs.MoveFirst
Do While Not rs.EOF
ingragsoc = rs.Fields(0)
path = "C:\Users\diego.macaluso\Desktop\EXEPE"
file = "\Listino Tetris Consolidation export Maggio 2016" & " " & ingragsoc & ".pdf"
Dim fulpafi As String
fulpafi = path & file
 
DoCmd.OpenReport repName, acViewPreview, , "[Q_Retrieve nolo export]![ragione sociale] ='" & ingragsoc & "'"
DoCmd.OutputTo acOutputReport, , acFormatPDF, fulpafi
DoCmd.Close acReport, repName
 rs.MoveNext
 Loop
End If
rs.Close
Set rs = Nothing
Set db = Nothing
 End Sub
Thanks again in advance for any hint someone will throw me :)

Ciao!
 
Do the bad names have symbols in them? Can you create a file path manually using the names? My theory is they have something that causes an error trying to save as a file.
 
Thanks Paul!
A stupid "*" was hidden in the name of a Customer and made it all stop working!

Thanks, this is solved!
 

Users who are viewing this thread

Back
Top Bottom