Results 1 to 8 of 8

Thread: Code Problem

  1. #1
    Join Date
    Jan 2004
    Posts
    68

    Unanswered: Code Problem

    Can anyone help, i modified this code so that if All the variables (Addressbox.value) are correct the email would send and if they werent an error message will appear instead of going to the debug vb screen. here is the code, im not v. good at vb and i dont know why this isnt working


    Code:

    Private Sub Email_Click()


    If izyMailer(False, AddressBox.Value, SubjectBox.Value, BodyBox.Value) Then
    MsgBox "The Email has sent to its correct destination"

    Else
    If izyMailer(True, AddressBox.Value, SubjectBox.Value, BodyBox.Value) Then
    MsgBox "Please Enter Criteria", vbOKOnly, "Error Trying To Send"

    End If
    End Sub

  2. #2
    Join Date
    Jan 2004
    Posts
    68

    Code Error

    By the way this is a call for a global module and this si the original call for it:

    private sub YourButton_Click()
    if izyMailer(False, addressBox.value, subjectBox.value, bodyBox.value) then
    msgbox "your mail got sent"
    else
    msgbox "ooops!"
    endif
    end sub

  3. #3
    Join Date
    Jan 2004
    Posts
    68

    IF IT HELPS...

    Here is the Glob Module



    Public Function izyMailer(isDraft As Boolean, isTo As String, isSubj As String, isBody As String, Optional isFile As String = "NONE") As Boolean
    'function requires:
    ' isDraft TRUE saves the mail in drafts, FALSE sends immediate
    ' isTo the recipient's mail address (addrFirst; addrMiddle; addrLast if a distribution list)
    ' isSubj the mail subject
    ' isBody the mail body text
    'and optionally accepts
    ' isFile the drive:/path/name.extension of a file to attach
    'caller is responsible for validating isFile
    'function returns TRUE on success, else FALSE


    On Error GoTo err_izyMailer

    Dim objOutlook As Outlook.Application
    Dim objOutMail As Outlook.MailItem
    Dim objOutDist As Outlook.Recipient
    Dim objOutFile As Outlook.Attachment

    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutMail = objOutlook.CreateItem(olMailItem)

    Set objOutDist = objOutMail.Recipients.Add(isTo) 'make distribution list
    objOutDist.Type = olTo

    objOutMail.Subject = isSubj 'make subject

    objOutMail.Body = isBody 'make message body

    If Not isFile = "NONE" Then Set objOutFile = objOutMail.Attachments.Add(isFile) 'attachment

    objOutMail.Save 'save as draft
    If Not isDraft Then objOutMail.Send '...and possibly send

    izyMailer = True 'success return

    exit_izyMailer:
    Set objOutDist = Nothing 'tidy up
    Set objOutFile = Nothing
    Set objOutMail = Nothing
    Set objOutlook = Nothing

    Exit Function 'and exit

    err_izyMailer:
    izyMailer = False 'failure return
    MsgBox Err.Description, vbCritical, "Error With System"
    Resume exit_izyMailer

    End Function

  4. #4
    Join Date
    Feb 2002
    Posts
    403
    Code:
    Private Sub Email_Click()
    
    
    If izyMailer(False, AddressBox.Value, SubjectBox.Value, BodyBox.Value) Then
    
    MsgBox "The Email has sent to its correct destination"
    
    Else
    
    MsgBox "Please Enter Criteria", vbOKOnly, "Error Trying To Send"
    
    End If
    End Sub

  5. #5
    Join Date
    Jan 2004
    Posts
    68
    i dunno why the but when i click email with no criteria the debug screen stil appears

  6. #6
    Join Date
    Feb 2002
    Posts
    403
    Where is the debug window taking you when you click debug? I have not checked your function.

  7. #7
    Join Date
    Jan 2004
    Posts
    68
    Taking me to this line

    If izyMailer(False, AddressBox.Value, SubjectBox.Value, BodyBox.Value) Then

  8. #8
    Join Date
    Feb 2002
    Posts
    403
    First thing to do is to drop BodyBox.Value. This is optional and you may be sending a message instead of a file or something.

    Separate the IzyMailer out of the IF then statement.

    Check the values of all parameters are actually returning values first.

    If these steps do not work, create a temp example and zip up and post.

Posting Permissions

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