UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Runtime Error 2501, Access 2016    
 
   
7MoonSage
post Jun 26 2019, 12:02 PM
Post#1



Posts: 18
Joined: 25-April 19



I have a button set up on a form with an 'On Click' Event.

I'm trying to get the button to save a report to a network drive, and the above runtime error is what I'm getting in response. I tried it with a local drive as well because I thought maybe the network drive was causing the issue. The code is listed below and the problem line is underlined,

Private Sub cmdPreview_Click()
If Me.Dirty Then Me.Dirty = False
Dim strDocName As String
Dim strWhere As String
strDocName = "MSO"
strWhere = "[HINID]=" & Me.HinID

DoCmd.OutputTo acOutputReport, "MSO", acFormatPDF, "C:\Users\DFord\Documents\MSO Reports" & " - " & Date & " - " & [HinID] & ".pdf"

DoCmd.OpenReport "MSO", acPreview, , "[HINID]=" & Me.HinID
End Sub

Before I added these command lines, all the button did was Print Preview the report on click. My end goals is to have it Print and Save to the network at the same time as individual documents and files. Each report is an individual document, so I'd like to avoid printing ALL the previous reports and saving ALL the previous reports to one file every time the button is pressed.

Can anyone offer a bit of guidance with this?
This post has been edited by 7MoonSage: Jun 26 2019, 12:02 PM
Go to the top of the page
 
theDBguy
post Jun 26 2019, 12:09 PM
Post#2


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi. Is HinID numeric or alphanumeric?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 12:17 PM
Post#3



Posts: 18
Joined: 25-April 19



Hey DBGuy!

Its alphanumeric.
Go to the top of the page
 
theDBguy
post Jun 26 2019, 12:28 PM
Post#4


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Okay, I thought so. You need to make sure none of the values contain any invalid characters for use as a filename.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 12:34 PM
Post#5



Posts: 18
Joined: 25-April 19



I just checked to verify and tried again. Got the same error.
Go to the top of the page
 
theDBguy
post Jun 26 2019, 12:39 PM
Post#6


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


To find out what's really happening, you'll have to step through the code. Do you know how to do that?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 12:48 PM
Post#7



Posts: 18
Joined: 25-April 19



I do not, and also this line turned red when I moved some things around.

DoCmd.OutputTo acOutputReport, "MSO", acFormatPDF, "C:\\Users\DFord\Documents\MSOReports"&" - "&[Date]&" - "&[HIN]&" ".pdf"

Its highlighting the period before pdf and saying Compile Error, expected End of Statement
Go to the top of the page
 
theDBguy
post Jun 26 2019, 12:56 PM
Post#8


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Okay, instead, can you post a sample copy of your db with test data?

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 01:10 PM
Post#9



Posts: 18
Joined: 25-April 19



Please see attached.
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 01:12 PM
Post#10



Posts: 18
Joined: 25-April 19



Oh, it appears the site is not letting me upload the attachment as a zip. Its too large otherwise....
Go to the top of the page
 
theDBguy
post Jun 26 2019, 01:22 PM
Post#11


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi. See if you can create a small demo, only including the necessary objects to troubleshoot this particular problem.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 01:57 PM
Post#12



Posts: 18
Joined: 25-April 19



I received new VB from a friend that works,

Private Sub cmdPreview_Click()
If Me.Dirty Then Me.Dirty = False
Dim strDocName As String
Dim strWhere As String
strDocName = "MSO"
strWhere = "[HINID]=" & Me.HinID

DoCmd.OutputTo acOutputReport, "MSO", acFormatPDF, "C:\Reports\MSO.pdf"

DoCmd.OpenReport "MSO", acPreview, , "[HINID]=" & Me.HinID
End Sub


So I guess my next question is how do you set the VB to make the filename Date-HIN?
Go to the top of the page
 
theDBguy
post Jun 26 2019, 02:10 PM
Post#13


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


QUOTE
So I guess my next question is how do you set the VB to make the filename Date-HIN?

Hi. The way you were doing it was correct. So, I guess even if you use the new code, if you use the HIN in the filename, you might get the same error again.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 
7MoonSage
post Jun 26 2019, 03:10 PM
Post#14



Posts: 18
Joined: 25-April 19



This one works,

DoCmd.OutputTo acOutputReport, "MSO", acFormatPDF, "\\BK100\Production\MSOReports\MSOReport" & " - " & Format(Date, "\#mm\-dd\-yyyy\#") & " - " & [HIN] & ".pdf"

The issue is you have to set a date format that can be used as a filename. The default format with the date syntax causes the error.

Thanks for your help!!!
Go to the top of the page
 
theDBguy
post Jun 26 2019, 03:15 PM
Post#15


Access Wiki and Forums Moderator
Posts: 76,000
Joined: 19-June 07
From: SunnySandyEggo


Hi. Glad to hear you got it sorted out. Good luck with your project.

--------------------
Just my 2 cents... "And if I claim to be a wise man, it surely means that I don't know" - Kansas
Access Website | Access Blog | Email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    18th August 2019 - 05:03 PM