Database problem (1 Viewer)

CosmaL

Registered User.
Local time
Today, 09:14
Joined
Jan 14, 2010
Messages
92
Hello my friends!

In my database (in a server with the appropriate user control, (single database file, not splitted), i got a sub which exports a report as a pdf and then creates an email with the report and another excel file (total 2 attachements).

My problem is that in my computer (win 10, office 2013) it's working fine.
When i run the database on another computer (win 10, office 2016 without access, we use access environment 2013), when i run the sub i got the error 2501, path doesn't exist. Looking in the folder, the report has been created but then i got the error.

Both users have the same access in the database folder/subfolders.

Below is the code:

Private Sub Command75_Click()
On Error GoTo Err_Command75_Click

Dim MailRecipientTemp, MailSubject, Respo As String
Dim MailRecipient, ccResipient As String
Dim CustomerT, TypeT, CustomerD, TypeD As String
Dim stDocName As String
Dim objOutlook As Object
Dim objEmail As Object
Dim todayDate, filename, filename1 As String
Dim strBody As String
Dim strEmail, strEmailCC As String
Dim strSubject As String
Dim strPathAttach, strPathAttach1 As String

Const olMailItem As Integer = 0

Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(olMailItem)

stDocName = "RespoIncomeSampleDate"

todayDate = Format(Date, "DDMMYYYY")

filename = "c:\temp\Customer Samples\PDF" & "" & stDocName & "_" & todayDate & ".pdf"

DoCmd.OutputTo acReport, stDocName, acFormatPDF, filename, False

filename1 = "c:\temp\Customer Samples\SampleAnalysisRequest.xlsx"

MailRecipientTemp = Me.[Responsible person]


Select Case MailRecipientTemp
'Select users for mail
End Select


MailSubject = "Report"

strEmail = MailRecipient
strSubject = MailSubject
strBody = "Dear " & Respo & vbCrLf & vbCrLf & "Attached you may find the report for the new sample(s), along with the 'sample analysis request form', which you are kindly requested to complete and return it back to me." & vbCrLf & "Best Regards,"
strPathAttach = filename
strPathAttach1 = filename1

objEmail.To = strEmail
objEmail.cc = ccResipient
objEmail.Subject = strSubject
objEmail.Body = strBody

With objEmail.Attachments
'use parenthisis around the path
.Add (strPathAttach)
.Add (strPathAttach1)
End With


objEmail.Display


Set objOutlook = Nothing
Set objMailItem = Nothing

Exit_Command75_Click:
Set objOutlook = Nothing
Exit Sub

Err_Command75_Click:
MsgBox Err & ": " & Err.Description
Resume Exit_Command75_Click
End Sub

Any ideas?

Thanks!!!!!!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:14
Joined
May 7, 2009
Messages
19,228
see your "filename" variable.
you are missing one backslash (\).
should be:

filename="c:\temp\Customer Samples\PDF\" & stDocName & "_" & todayDate & ".pdf"
 

CosmaL

Registered User.
Local time
Today, 09:14
Joined
Jan 14, 2010
Messages
92
I've corrected it but i still get the message.

When i compile it, i don't get any errors in the code.

Should there be any mulfuction between the office versions?
 

jleach

Registered User.
Local time
Today, 02:14
Joined
Jan 4, 2012
Messages
308
Most times for development I'll try early binding first, then switch to late binding for testing/distribution. Perhaps you could try that (add a reference to Outlook and change your Object types to their appropriate strong types, develop and test it all, then change back to Object).

Also, just to be sure: you do have Option Explicit at the top of this (and all) modules?
 

JHB

Have been here a while
Local time
Today, 08:14
Joined
Jun 17, 2012
Messages
7,732
Are you sure the path actually exist at the problem computer?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:14
Joined
May 7, 2009
Messages
19,228
on this part:

objEmail.To = strMail
objEmail.cc = ccResipient
objEmail.Subject = strSubject
objEmail.body = strBody


check objEmail.cc, do you have the variable ccResipient?
 

Gasman

Enthusiastic Amateur
Local time
Today, 07:14
Joined
Sep 21, 2011
Messages
14,221
The report might have been created, but does this exist?
Code:
filename1 = "c:\temp\Customer Samples\SampleAnalysisRequest.xlsx"
 

CosmaL

Registered User.
Local time
Today, 09:14
Joined
Jan 14, 2010
Messages
92
Hello,

problem solved. For a reason it stopped in this part: strPathAttach1 = filename1
I changed to "manual" strPathAttach1 = "c:\temp\Customer Samples\SampleAnalysisRequest.xlsx" and it worked.

jleach: Option explicit was "missing", added in the top of the module.
JHB: I've created the path before running the database
arnelgp: variable ccResipient, is ok, there was a typing error and i kept it that way (i use only in this module).
Gasman: Both files exist.

Thank you all for your help!!!!
 

JHB

Have been here a while
Local time
Today, 08:14
Joined
Jun 17, 2012
Messages
7,732
Only for info:
Code:
Dim MailRecipientTemp, MailSubject, Respo As String
Only the Respo is declared as string, the rest is Variant type.
You've to assign the type after each variable, like below.
Code:
Dim MailRecipientTemp [COLOR=Red]As String, [/COLOR]MailSubject [COLOR=red]As String[/COLOR], Respo As String
 

CosmaL

Registered User.
Local time
Today, 09:14
Joined
Jan 14, 2010
Messages
92
I will correct it, i have the same way of declarations in 2-3 modules.

Thnaks!!!
 

Users who are viewing this thread

Top Bottom