Else Issues (1 Viewer)

KevlarKev

Registered User.
Local time
Today, 11:06
Joined
Jan 16, 2013
Messages
26
Hello everyone, can someone please point out what I am doing wrong?

I have some VBA which I have attached to a button. When the button is clicked the VBA should look to see if a specific text box on a form contains "None" and if so it should open an email which pulls fields from the open form.

If the text box contains anything other than "None" then it opens a different email which pulls fields from the open form.

Both of the VBA work on thier own if attached to different buttons so I know there is nothing wrong with the actual email code.

The problem is combining them into one VBA IF statement. When I do that and click on the button it opens the debugger and highlights the ELSE statement saying "Else without If"

I have tried everything I can think of to fix this. Can you see what I am missing? I really need help!!!

PHP:
Private Sub Image167_Click()

If Form_frmEmailSampleDelivery.Text8 = "None" Then

Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = "AllStaff"
.CC = ""
.BCC = ""
.Subject = "Samples Received - Unknown Project!"
.Body = Form_frmEmailSampleDelivery.Text117 & " " & "boxes of samples have been delivered but no project has been identified. The interval is from" & " " & Form_frmEmailSampleDelivery.Text113 & " " & Form_frmEmailSampleDelivery.Combo139 & " " & "to" & " " & Form_frmEmailSampleDelivery.Text114 & " " & Form_frmEmailSampleDelivery.Combo139 & ". The boxes are marked for well" & " " & Form_frmEmailSampleDelivery.Combo135 & ". Please contact Labs as soon as possible if you recognise these samples."
.Display

Else

Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
With OutMail
.To = Form_frmEmailSampleDelivery.Text8
.CC = ""
.BCC = ""
.Subject = "Samples Received!"
.Body = "Samples have been received and booked in for " & Form_frmEmailSampleDelivery.Text9 & " - " & Form_frmEmailSampleDelivery.Text7 & ". Please log in to PIMS to review the samples and inform Labs when you require them to be listed. Please note that if the project does not have a valid purchase order then Labs will not list samples unless authorised by a Director."

.Display

End With
On Error GoTo 0

End Sub
 

pr2-eugin

Super Moderator
Local time
Today, 19:06
Joined
Nov 30, 2011
Messages
8,494
Try this code,
Code:
Private Sub Image167_Click()
   [COLOR=Red] Dim OutApp As Object
    Dim OutMail As Object
    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)[/COLOR]
    
    If Form_frmEmailSampleDelivery.Text8 = "None" Then
        With OutMail
            .To = "AllStaff"
            .CC = ""
            .BCC = ""
            .Subject = "Samples Received - Unknown Project!"
            .Body = Form_frmEmailSampleDelivery.Text117 & " boxes of samples have been delivered but no project has been identified. " & _
                    "The interval is from " & Form_frmEmailSampleDelivery.Text113 & " " & Form_frmEmailSampleDelivery.Combo139 & _
                    " to " & Form_frmEmailSampleDelivery.Text114 & " " & Form_frmEmailSampleDelivery.Combo139 & _
                    ". The boxes are marked for well " & Form_frmEmailSampleDelivery.Combo135 & _
                    ". Please contact Labs as soon as possible if you recognise these samples."
            .Display
        [COLOR=Red][B]End With[/B][/COLOR]
    Else
        With OutMail
            .To = Form_frmEmailSampleDelivery.Text8
            .CC = ""
            .BCC = ""
            .Subject = "Samples Received!"
            .Body = "Samples have been received and booked in for " & Form_frmEmailSampleDelivery.Text9 & " - " & Form_frmEmailSampleDelivery.Text7 & _
                    ". Please log in to PIMS to review the samples and inform Labs when you require them to be listed. " & _
                    "Please note that if the project does not have a valid purchase order then Labs will not list samples unless authorised by a Director."
            .Display
        End With
    [COLOR=Red][B]End If[/B][/COLOR]
End Sub
 

KevlarKev

Registered User.
Local time
Today, 11:06
Joined
Jan 16, 2013
Messages
26
Hi Pr2, thank you for you assistance.

I pasted the code and now it highlights the first *end with* and tells me I have a syntax error.

Any ideas?
 

KevlarKev

Registered User.
Local time
Today, 11:06
Joined
Jan 16, 2013
Messages
26
Actually I just sorted it. I pasted the text in wrong!

Thank you for your help!!!!

Kevin.
 

pr2-eugin

Super Moderator
Local time
Today, 19:06
Joined
Nov 30, 2011
Messages
8,494
End With <> Syntax error. Check again !

EDIT : Seen that you have realized your mistake ! Good luck.
 
Last edited:

Brianwarnock

Retired
Local time
Today, 19:06
Joined
Jun 2, 2003
Messages
12,701
Kevin just for the record you had an
End With
Missing in your original code, hence the else was not related to the if

Brian
 

Users who are viewing this thread

Top Bottom