Could you post the code you're referring to Rebecca. You may mean the [Attachment Variable].PathName, but you posted Attachment.Path Name. If you're actually tryng to use that as your code you'd have a problem as Attachment is a class and not an object. It's hard to say what might be wrong without seeing a bit of your code.
Saving attachment location to Access table - filepath code?
Collapse
X
-
Code:For Each Atmt In MailObject Set rstAttachments = db.OpenRecordset("tbl003_Attachments") rstAttachments.AddNew intAttachmentID = rstAttachments!AttachmentID rstAttachments!RequestID = strRequestID rstAttachments!AttachmentLocation = Atmt.PathName rstAttachments!createduserstamp = gstrFullName rstAttachments!createddatestamp = Now Debug.Print strRequestID Next
Comment
-
This code seems to be about creating an attachment to add to an email item. I thought you wanted to determine the path of a pre-existing attachment item. As this code doesn't include any reference to .FullPath in it anywhere either, I'm struggling to see where it fits into the conversation.
I'm sure this is proving complicated for you, and I'd like to help, but I'm still struggling to understand where you're coming from, so it's hard for me to know how to. If you go back to your post #15 it says :
Originally posted by Rebecca McCallanRebecca McCallan:
Basically, when I try and use Attachment.Path Name it returns a blank string...=[
PS. Forget this post. I just reread back over the thread and realised I'd made the mistake that got me confused when I responded to your earlier post. Give me some time to reread things and see where I really should be at. At first glance, my property name understandings were all confused, but I think the fact that the code is creating a new attachment will prove important.Comment
-
Right. I think I'm back on track now (Ironic as I've just come in from an evening out, which included some alcoholic beverages, whereas when I posted my earlier rubbish I was stone cold sober).
The .AddNew is not a problem after all. That's another thing I completely misinterpreted (I'm really not happy with the number of errors I've made already on this thread). In fact, I see no reason why the code should behave as you've described.
Ah, I think I may be seeing some light at the end of the tunnel now. I think line #6 is fine, but line #1 is treating the MailItem object (MailObject) as an attachment collection, when really it is simply an object that contains such a collection called Attachments. Try the following for line #1 and see if that helps any :
Code:For Each Atmt In MailObject.Attachments
Comment
-
Hmmm.... The code I posted to you appends rstAttachments with the details from the email and in these details I want to include the attachment path (Just wanted to clear that up but I think you've got it now!) Secondly, I'm not sure where .FullPath came into this, you did mention it earlier but I did think you were referring to PathName? So I'm not sure what I should do with this. Anyway, I changed line 1 to 'For Each Atmt In MailObject.Atta chments' and though Atmt.PathName still returned an empty string, on hovering over 'Atmt' it returned the FileNAME... which is a start as it wasn't even doing that before! I can't work out why the PathName is returning an empty string because I have made sure the emails in my inbox have Attachments and surely if they didn't have attachments the 'For' would just be skipped anyway so for it to enter the loop there must be attachments present... Hmmmm.... =[ Cheers.Comment
-
Originally posted by Rebecca McCallanRebecca McCallan:
I'm not sure where .FullPath came into this,
I checked the help file for the PathName property, and it says :
Returns a String representing the full path to the linked attached file. This property is only valid for linked files. Read-only.
I assume from this that your attachment isn't what is termed a linked attached file, though I can't honestly say what that would be if different from a standard attachment (I would expect any attachment to be such, but who knows).
The help for the FileName property however, is :
Returns a String representing the file name of the attachment. Use this property in conjunction with the PathName property. Read-only.
This indicates perhaps that the PathName is required after all. Somewhat confusing after what you report. Is there any chance that the mail item you're dealing with is somehow still in the process of being created? I can only imagine these properties may not be set until after the MailItem has been saved away. I'm scrabbling in the dark somewhat, to be fair. I haven't anything I can reproduce this on so can't look at anything in detail or do any meaningful tests for you.
I suggest you look at some of the properties that are available when you have the attachment object available to you in the code, and maybe look into testing first with older items, if you're not already.Comment
-
I also read something about a 'linked file' but I'm not sure what that means... I have been testing this on normal emails - my daily emails in my inbox, not 'test' emails so they are just normal emails with normal attachments so I can't work out why the pathname propery won't work =/Comment
-
Such as the message body and sender email etc? Yes, I have it all working and when I went on to add in the attachment location it didn't work as I thought it should =[Comment
-
Oh right sorry, yeah I've just tested that .FileName and .DisplayName both return the same value (the filename).Comment
-
Frankly I'm out of ideas. This sort of thing works best when I'm working from experience, or I have something to work with (that I can run various tests on as ideas occur). Working remotely on a setup I'm unfamiliar with gives me none of those advantages, so I will continue to monitor the thread in case anything comes up (either to enlighten or that I can contribute to) but I can't offer any further ideas at this time. Sorry. I just don't know why that particular property is not being populated. There is nothing to indicate why in the Help.Comment
-
-
If you ever wanted to drop your project in here for me to look at (See post #11) I may be able to make more progress. Otherwise, I'll try to remember this thread if ever I come across a solution.
Actually, I do have another option. I'll post a link to here in the experts' area and see if anyone else can throw any more light on the subject.Comment
-
Rebecca,
NeoPa is usually so much on the mark that none of us spent any time on this thread once we saw he was on the case. We thought he'd wrap it up in a jiffy. But, even Superman has to look out for kryptonite once in a while. :)
I found a thread that might be helpful. It offers another way to get what you want, I think ... it demonstrates how to read through your emails and save the attachments where you want to put them. So, your code could do that and then it would know what to save in your attachments table.
This is a reminder that even if you have opened the email and saved the attachment somewhere, that's not where the email's attachment is. That's where the copy of the attached file is. The email attachment itself is still (I guess) in the Outlook.pst file with the rest of the email.
Here's some of the code from the thread:
Code:Set myfolder = _ myNameSpace.GetDefaultFolder(olFolderInbox) For Each myItem In myfolder.Items If myItem.Subject = strSubject And myItem.UnRead Then With myItem Set objAttachments = myItem.Attachments For Each Attachment In objAttachments strFile = "C:\Saved Files\" & Attachment.DisplayName Attachment.SaveAsFile (strFile) strSaved = "Saved to " & strFile & " on " & Now() Next
What might also be helpful to you is to know you can use the ENVIRON function to get the user's working path for documents. This thread helps with that:
Hope this helps.
JimComment
Comment