Question

I am back with another fun challenge.

Process:

  1. I get a daily email message with an attachment (about 1MB in size). I have all the emails being via an outlook rule to the same directory.
  2. Detach attachment and process the file giving it a specific name
  3. combine all into a single large file
  4. load file into database table

current tools

  • Outlook macro to detach attachment
  • cygwin to do some file processing
  • access to stage the data
  • SQL import to move the data from Access to SSIS
  • laptop has 24MB in RAM so doing something in memory is not an issue.

Desired flow

  • VBA macro to detach the attachment, process the file, load file into the database there by eliminating cygwin and access.
  • or some other single click option. heck, vbs might work too but I haven't worked with that language before. maybe powershell (another one I haven't used)?

text processing

  • each file has a header that is always 3 rows so I need to remove them
  • sometimes the 4th row has bad data and I just need to skip it
    • good row: xxxx | xxxx | xxxx | 3000 | xxxx | xxxx |
    • bad row: xxxx | xxxx | xxxx | 7000 | xxxx | xxxx |
    • if the 3000 value is greater than 6000, I want to skip it

what I have so far is a macro that will detach the attachment and name it as I want. While I am not looking for the answer in code, I was to write that myself for the education of it, I am at a loss as to what tools the solution entails or where to start looking. I was thinking one of two ways:

  • do this all through an outlook macro

or

  • use an SSIS package but I don't know if a package can access my inbox.

thank you very much for anything thoughts/suggestions you might have

Michael.

------------ Update 1 -------------

Trying to chunk this out. Since I have the attachment code, I am trying to open the file after I save it. I could do the processing then append it to another file. I can't seem to figure out how to open the attachment directly from the email. Do I have to save it first? I am trying this but get a type mismatch

FileName = "C:\Users\xxxxxxx\Desktop\OSTAT_import\" & Format(DateAdd("d", -1, Item.ReceivedTime), "yyyymmdd") + "_OSTATLOG_RAW.TXT"

Open FileName For Append As lFile
    Print #lFile, "first line of text"
Close lFile

Error Number: 13 Error Description: Type mismatch

Was it helpful?

Solution

Ha! Got a good one... I stumped the experts ;). I am going to close this out. I think that since I have the code to strop the attachments, I might just use an SSIS packages to foreach the files and load them. It is probably the easiest way to go. Cheers.

For the record, I had got the file open and was able to write a file but never was able to get the processing I wanted done. I think that I could have figured it out but sometimes it is better to take a different route than be stuck on a single approach.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top