sql server 2008 - how to insert rows from VBA using Outlook rule -


my code worked fine until changed office 2010 2013

this code exports attachments , runs script inserts information in sql server against exported file.
file not exporting, no sql entry. no life.

'addin outlook rules export attachments disk 'raw component of outlook attachment strip 'compiled muhammad abubakar riaz/com/lhr make life lit bit easier  sub rc_outlookattachmentstrip(anitem outlook.mailitem)      dim anattachedobject outlook.attachment      'location of folder want save attachments      dim pathlocation string     pathlocation = "g:\foi files\junk"      'date & time add attached file name      nowdate = format(now, "dd-mm-yyyy")     nowtime = format(now, "hh-mm am/pm")      'random counter minimize overwriting same file names in same folder      randomcounter = cint(int((9999 * rnd()) + 1))     filecounter = 0      'email received @      receivetime = anitem.receivedtime     fromid = anitem.sendername      'sql connection code      const adopenstatic = 3     const adlockoptimistic = 3      set objconnection = createobject("adodb.connection")     set objrecordset = createobject("adodb.recordset")      objconnection.open _     "provider = sqloledb; " & _         "data source=c-lhe-cs-68541\cmsa;" & _         "trusted_connection=yes;" & _         "initialcatalog=cmsa_console;" & _         "user id=sa;password=xxxxxxxxx;"      '-------------------------     'ended sql connection code      'save files 1 one      each anattachedobject in anitem.attachments         filecounter = filecounter + 1          'fixed files types exported, in case text files         if right(anitem.attachments.item(filecounter).filename, 4) = ".txt"              'save files 1 one             'file format 1-9999 date time originalfilename.extension             anattachedobject.saveasfile pathlocation & "\" & filecounter & "-" & randomcounter & " " & nowdate & " " & nowtime & " " & anitem.attachments.item(filecounter).filename              'create query string             myfilename = anitem.attachments.item(filecounter).filename             sqlquery = "insert [cmsatemp].[dbo].[temptest] values('" & fromid & "','" & receivetime & "','" & myfilename & "')"              'insert records db             objrecordset.open sqlquery, _             objconnection, adopenstatic, adlockoptimistic          end if             set anattachedobject = nothing     next      objconnection.close  end sub 

i forgot debugging useful. found logical error - file extension .csv not .txt - works fine now.

    'fixed files types exported, in case text files     if right(anitem.attachments.item(filecounter).filename, 4) = ".csv" 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -