Results 1 to 3 of 3
  1. #1
    cgschlangen
    Guest

    If Then Else problem... (Access 2000)

    Greetings weekend loungers...
    I'm lucky enough to be at work this beautiful weekend and am working on my database... Can anyone help me w/ this code?
    For some reason it keeps skipping to the Nobravo section of code... even when there is a bravo file...

    Private Sub MailFile_Click()

    'Create outlook e-mail message:
    Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookAttach As Outlook.Attachment
    Dim objAttachment
    Dim bravofile As String
    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)


    If IsNull(Me.EFile.Value) Then
    bravofile = emptystring
    Else
    bravofile = Me.EFile.Value
    End If
    alphafile = Me.File.Value
    checkfilea = Dir(CurrentProject.Path + "Files" + "" + alphafile)
    checkfileb = Dir(CurrentProject.Path + "files" + "" + bravofile)
    If checkfilea <> alphafile Then GoTo Err_MailFile

    <span style="background-color: #FFFF00; color: #000000; font-weight: bold">If IsNull(Me.EFile.Value) & bravofile <> checkfileb Then
    GoTo Nobravo
    Else
    GoTo WithBravo
    End If</span hi>

    End_This_Sub:
    Exit Sub

    'If Bravofile value exists:
    WithBravo:
    With objOutlookMsg
    .Attachments.Add CurrentProject.Path + "files" + "" + Me.File.Value
    .Attachments.Add CurrentProject.Path + "files" + "" + Me.EFile.Value
    .Display
    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    DoCmd.Restore
    GoTo End_This_Sub

    'If bravo file doesn't exist:
    Nobravo:
    With objOutlookMsg
    .Attachments.Add CurrentProject.Path + "files" + "" + Me.File.Value
    .Display
    End With
    Set objOutlookMsg1 = Nothing
    Set objOutlook1 = Nothing
    DoCmd.Restore
    GoTo End_This_Sub

    Err_MailFile:
    MsgBox "Could not locate file. Check with OSOW to make sure it was saved to the proper location and is named properly.", vbExclamation
    GoTo End_This_Sub


    End Sub

    I've done enough troubleshooting to figure out that for some reason the if statement (highlighted) automatically jumps to NoBravo ... but can't figure out why it would disregard the if statement?
    Any thoughts?

    Thanks in advance
    Dan

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: If Then Else problem... (Access 2000)

    & is the string concatenation operator. If you want to combine logical conditions, use And:

    If IsNull(Me.EFile.Value) And bravofile <> checkfileb Then

    Note: why not avoid the GoTo's and place the instructions in the If ... Then ... Else ... End If:

    With objOutlookMsg
    .Attachments.Add CurrentProject.Path + "files" + "" + Me.File.Value
    If IsNull(Me.EFile.Value) And bravofile <> checkfileb Then
    Else
    .Attachments.Add CurrentProject.Path + "files" + "" + Me.EFile.Value
    End If
    End With
    .Display
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    DoCmd.Restore
    Exit Sub

  3. #3
    cgschlangen
    Guest

    Re: If Then Else problem... (Access 2000)

    Bah... Common sense... Who needs it?!?!?
    hehehe...
    Thanks Hans - You're a life saver...

Posting Permissions

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