Results 1 to 2 of 2

Thread: Error attaching file to outlook

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2003
    Location
    Florida
    Posts
    104

    Error attaching file to outlook

    I am having a problem when I try to attach a file to my outlook. If I direct a path, no problem. Below is where the error is. Thanks

    Code:
    Option Explicit
    
    Dim FileToAttach As String
    Dim ActualNumberOfOccurrences As Integer
    Dim AnsParseStr As String
    Dim position As Integer
    Dim NumCharInString As Integer
    Dim checkit As Boolean
    Dim RetVal As Variant
    
    Private Sub cmdBrowse_Click()
    
    '***********************************************************************
    'Give the file selection window a title.
        cdlOpen.DialogTitle = "Pick A File To Attach To Outlook Express"
        'The file selection window will start in the
        'applications directory.
        cdlOpen.InitDir = App.Path
            
        'Show all files
        cdlOpen.Filter = "All Files (*.*)|*.*"
                           
        'Open the file selection window.
        cdlOpen.ShowOpen
        
        FileToAttach = cdlOpen.FileName
    
        position = 1
    
    Do Until position = 0
    
       position = InStr(position + 1, FileToAttach, "\")
       ActualNumberOfOccurrences = ActualNumberOfOccurrences + 1
      
    Loop
      
    'Parse the string to get the part after the last backslash \
     AnsParseStr = ParseStr(FileToAttach, "\", ActualNumberOfOccurrences, ActualNumberOfOccurrences)
      
    
     '****************************************************************
        'Check to see if a file has been selected.
        Select Case FileToAttach
        
           Case vbNullString
                'Do not allow empty strings.
                checkit = False
                Exit Sub
                
            Case Else
                checkit = True
                lblShortPath.Visible = True
                lblShortPath = AnsParseStr
                
        End Select
    
    End Sub
    
    Private Sub cmdEnd_Click()
        Unload Me
    End Sub
    
    Private Sub Command1_Click()
    
    Dim o
    Dim m
    
    Set o = CreateObject("Outlook.Application")
    Set m = o.CreateItem(0)
    
    m.To = "[email protected]"
    m.Subject = "This is the Subject"
    m.Body = "File Attached"
    
    m.Attachments.Add = lblShortPath.Caption Code:
    1. m.Attachments.Add = lblShortPath.Caption
    m.Display End Sub Function ParseStr(ByVal Text, ByVal separator, ByVal start As Integer, _ ByVal toEnd As Integer) As String Dim i As Integer, Temp As String, result As String Dim ParseStrBegin As Integer, t As Integer, Count As Integer Dim ParseStrEnd As Integer, Found As Integer ParseStr = "" If Text = "" Then Exit Function If separator = "" Then Exit Function If Not (start > 0) Then start = 1 If toEnd < start Then toEnd = start 'Find first instance of the separator t = InStr(1, Text, separator) 'If no occurence return original string and exit If t = 0 Then ParseStr = Text Exit Function End If 'If first ParseStr, return left most data and exit If (start = 1) And (start = toEnd) Then If t = 1 Then ParseStr = "" Exit Function Else ParseStr = Left(Text, t - 1) Exit Function End If End If ParseStrBegin = 1 For i = 1 To start - 1 t = InStr(ParseStrBegin, Text, separator) If t = 0 Then Exit For ParseStrBegin = t + 1 Next i ' If there is no separator exit function with "" result If t = 0 Then Exit Function 'If only one ParseStr to return, find it and exit If start = toEnd Then t = InStr(ParseStrBegin, Text, separator) If t = 0 Then t = Len(Text) + 1 result = Left(Text, t - 1) ParseStr = Right(result, t - ParseStrBegin) Exit Function End If 'Find last ParseStr then exit ParseStrEnd = t + 1 If start = 1 Then start = 2 For i = start To toEnd t = InStr(ParseStrEnd, Text, separator) If t = 0 Then t = Len(Text) + 1 Exit For End If ParseStrEnd = t + 1 Next i If t = 0 Then t = Len(Text) + 1 result = Left(Text, t - 1) ParseStr = Right(result, t - ParseStrBegin) End Function
    Attached Images Attached Images  
    Last edited by rnm89; Apr 21st, 2009 at 01:51 PM. Reason: added screenshot

  2. #2
    Addicted Member
    Join Date
    Apr 2009
    Location
    Toronto, Ontario
    Posts
    242

    Re: Error attaching file to outlook

    You need to tell us what error you get or what exactly is happening at the point your program has a problem. That will give us all a better idea of what's going on.

    Thanks.
    -EM

Posting Permissions

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



Click Here to Expand Forum to Full Width