Results 1 to 4 of 4

Thread: Please help

  1. #1
    Join Date
    Feb 2004
    Location
    Houston, TX
    Posts
    3

    Unanswered: Please help

    I created a sub in module, but I am having problems writing a function to call it. I think I am a VB idiot Please help!

    This is the sub code..How do I write a function to call it so that I can use the function in a macro?

    Sub SendEMail()

    Dim OutlookObj As Outlook.Application
    Dim Nms As Outlook.NameSpace
    Dim Mail As Outlook.MailItem


    Set OutlookObj = CreateObject("Outlook.application")
    Set Nms = OutlookObj.GetNamespace("MAPI")
    Set Mail = OutlookObj.CreateItem(0)
    Mail.Subject = "this is a test"
    Mail.Display

    End Sub

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346

    Re: Please help

    1) First make sure your sub is Public:

    Public Sub SendEmail()
    .
    .
    .
    End Sub

    2) To call it just type in the name:

    SendEmail

    or

    Call SendEmail()
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Feb 2004
    Location
    Houston, TX
    Posts
    3

    Re: Please help

    I got this to work..but when i created a macro to call the function, and tried to run it, Access does not recognize it. I believe the error msg was The expression you entered has a function name that the file name doesnt recognize.
    The module name and function aren't the same; I know that macro will NOT call a function if they are the same. Does anyone have any idea?






    Originally posted by HoustonGal
    I created a sub in module, but I am having problems writing a function to call it. I think I am a VB idiot Please help!

    This is the sub code..How do I write a function to call it so that I can use the function in a macro?

    Sub SendEMail()

    Dim OutlookObj As Outlook.Application
    Dim Nms As Outlook.NameSpace
    Dim Mail As Outlook.MailItem


    Set OutlookObj = CreateObject("Outlook.application")
    Set Nms = OutlookObj.GetNamespace("MAPI")
    Set Mail = OutlookObj.CreateItem(0)
    Mail.Subject = "this is a test"
    Mail.Display

    End Sub

  4. #4
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Re: Please help

    Hi there,

    Why even fool with a macro? Convert your macro to a Module, name that module something like SendMail() then call that macro from your function, IF you already know the macro will send the mail. Check online help for sending mail in access via outlook, using the SendObject action.

    Bud

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •