We help IT Professionals succeed at work.

how to reference a record set field within CDO syntax

Mark Drelinger
on
I'm trying to attach a file to an email via vbscript and CDO.  
The error is "Wrong number of arguments or invalid property assignment: 'objCDO.AttachFile'"

              objCDO.AttachFile (rsEQUIPInvoices.Fields.Item("InvoiceFileLocation").Value)

value from recordset is exactly as:
              "D:\inetpub\Media\EQUIP_Invoices\2019\12\13\I_I_229406.pdf"

I think its the way I'm referencing the field, but I can't remember the proper syntax.
Please advise.
Mark


Set objCDO = Server.CreateObject("Cdonts.NewMail")
objCDO.BodyFormat =0 ' 0 is a plain text, 0 "zero" is a HTML
objCDO.MailFormat = 0 ' 1 is a plain text, 0 "zero" is mime format

objCDO.From = Request("varFrom")
objCDO.To = Request("varTo")

objCDO.Subject = "Invoices from Schmidt Equipment"
objCDO.Body = "Invoices from Schmidt Equipment"

While ((Repeat1__numRows <> 0) AND (NOT rsEQUIPInvoices.EOF))
      objCDO.AttachFile=(rsEQUIPInvoices.Fields.Item("InvoiceFileLocation").Value)
        Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsEQUIPInvoices.MoveNext()
Wend

objCDO.Send
Set objCDO = Nothing
Comment
Watch Question

Most Valuable Expert 2012
Top Expert 2014
Commented:
Hi,

Is it typecasting correctly?

Try
objCDO.AttachFile CString(rsEQUIPInvoices.Fields.Item("InvoiceFileLocation").Value)

or, if it requires brackets
objCDO.AttachFile (CString(rsEQUIPInvoices.Fields.Item("InvoiceFileLocation").Value))

It only needs one required argument, so it should be OK:
https://docs.microsoft.com/en-us/previous-versions/exchange-server/exchange-10/ms527836(v%3Dexchg.10)

Regards,

Rob.

Author

Commented:
Thank you.