Setting Library Reference by code / Using CDOSYS in a .vbs file

Posted on 2011-05-12
Last Modified: 2012-05-11
Hello Experts,

I have the following code which is pretty simple and works in VB6, but when I copy it into a VBS file and comment out the 2 Form_Load lines I get the following error at line 22:

Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.

Also, in VB6 I can get the same error if I remove the reference to the Microsoft CDO Message library. I guess, my question should be how can I set a Reference to C:\windows\system32\cdosys.dll by code within my .vbs file?

Thank you,
'Option Explicit

Private Sub Form_Load() '**************COMMENT OUT FOR VBS******************
    Call testMail
End Sub '**************COMMENT OUT FOR VBS******************

Sub testMail()
    smtpServer = ""
    smtpUser = ""
    smtpPass = "testing"
    fromAddress = ""
    toAddress = ""
    body = "testing"
    subject = "cdo test"
     Set cdoConfig = CreateObject("CDO.Configuration")
     With cdoConfig.Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = smtpServer
        .Item(cdoSMTPAuthenticate) = 1
        .Item(cdoSendUsername) = smtpUser
        .Item(cdoSendPassword) = smtpPass
        '.Item("cdoSMTPServerPort") = 45
    End With

    Set cdoMessage = CreateObject("CDO.Message")
    With cdoMessage
        Set .Configuration = cdoConfig
        .From = fromAddress
        .To = toAddress
        .subject = subject
        .HTMLBody = body
    End With
    Set cdoMessage = Nothing
    Set cdoConfig = Nothing
    MsgBox "done."

End Sub

Open in new window

Question by:APD_Toronto
    LVL 65

    Accepted Solution

    Try adding these constants to your code:
    Const cdoSendUsingMethod = ""
    Const cdoSendUsingPort = 2
    Const cdoSMTPServer = ""
    Const cdoSMTPServerPort = ""
    Const cdoSMTPConnectionTimeout = ""
    Const cdoSMTPAuthenticate = ""
    Const cdoBasic = 1
    Const cdoAnonymous = 0
    Const cdoSendUserName = ""
    Const cdoSendPassword = ""



    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now