Need help with if .. else if statesment

I have the following code however , after the first if statement it does not go to the elseif..
   
If Me.FamilyMember > 0 Then
    objRecip.Resolve
        If objRecip.Resolved Then
            On Error Resume Next
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
           
                If Not objFolder Is Nothing Then
                    Set objAppt = objFolder.Items.Add
                        If Not objAppt Is Nothing Then
                            With objAppt
                                .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                                & "          " & DisplayNameFM & "  --  " & FamilyMember
                                .Start = Me!ApptDate & " " & Me!ApptTime
                                .Duration = Me!ApptLength
                                '.AllDayEvent = True
                        If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Family Member Main Phone: " & Mp3 & "  --  " & "Family Member Cell Phone: " & Cp3
                        If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                             .ReminderSet = True
                        End If
                            .Save
                            End With
                        End If
                        End If
ElseIf Me.PrimaryClientName > 0 Then
        objRecip.Resolve
            If objRecip.Resolved Then
            On Error Resume Next
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
           
                If Not objFolder Is Nothing Then
                    Set objAppt = objFolder.Items.Add
                        If Not objAppt Is Nothing Then
                            With objAppt
                                .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                                & "          " & DisplayNamePC & " -- " & PrimaryClientName
                                .Start = Me!ApptDate & " " & Me!ApptTime
                                .Duration = Me!ApptLength
                                '.AllDayEvent = True
                        If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Primary Client Main Phone: " & Mp2 & "  --  " & "Primary Client Cell Phone: " & Cp2
                       
                        If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                             .ReminderSet = True
                        End If
                            .Save
                            End With
                        End If
                        End If
               
End If
End If
End If
End If


 ' Release the Outlook object variable.
        Set outobj = Nothing
        Set objApp = Nothing
        Set objNS = Nothing
        Set objFolder = Nothing
        Set objDummy = Nothing
        Set objRecip = Nothing
        Set objAppt = Nothing
 ' Set the AddedToOutlook flag, save the record, display a message.
        Me.AddedToOutlook = True
        MsgBox "Appointment Added!"
   
End Sub
VGuerra67Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Hard to tell. Clean up your code first. Create a function to return your appointment. Create a sub to handle that appointment.
0
Robert ShermanOwnerCommented:
Please wrap sample code in code tags, this makes it readable and will get you a quicker response.   To move this along, I have taken your sample code and wrapped it below:

If Me.FamilyMember > 0 Then
    objRecip.Resolve
        If objRecip.Resolved Then
            On Error Resume Next
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
           
                If Not objFolder Is Nothing Then
                    Set objAppt = objFolder.Items.Add
                        If Not objAppt Is Nothing Then
                            With objAppt
                                .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                                & "          " & DisplayNameFM & "  --  " & FamilyMember
                                .Start = Me!ApptDate & " " & Me!ApptTime
                                .Duration = Me!ApptLength
                                '.AllDayEvent = True
                        If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Family Member Main Phone: " & Mp3 & "  --  " & "Family Member Cell Phone: " & Cp3
                        If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                             .ReminderSet = True
                        End If
                            .Save
                            End With
                        End If
                        End If
ElseIf Me.PrimaryClientName > 0 Then
        objRecip.Resolve
            If objRecip.Resolved Then
            On Error Resume Next
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
           
                If Not objFolder Is Nothing Then
                    Set objAppt = objFolder.Items.Add
                        If Not objAppt Is Nothing Then
                            With objAppt
                                .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                                & "          " & DisplayNamePC & " -- " & PrimaryClientName
                                .Start = Me!ApptDate & " " & Me!ApptTime
                                .Duration = Me!ApptLength
                                '.AllDayEvent = True
                        If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Primary Client Main Phone: " & Mp2 & "  --  " & "Primary Client Cell Phone: " & Cp2
                       
                        If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                             .ReminderSet = True
                        End If
                            .Save
                            End With
                        End If
                        End If
               
End If
End If
End If
End If


 ' Release the Outlook object variable.
        Set outobj = Nothing
        Set objApp = Nothing
        Set objNS = Nothing
        Set objFolder = Nothing
        Set objDummy = Nothing
        Set objRecip = Nothing
        Set objAppt = Nothing
 ' Set the AddedToOutlook flag, save the record, display a message.
        Me.AddedToOutlook = True
        MsgBox "Appointment Added!"
   
End Sub 

Open in new window

1
Rgonzo1971Commented:
HI,

pls try

If Me.FamilyMember > 0 Then
    objRecip.Resolve
    If objRecip.Resolved Then
        On Error Resume Next
        Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
        
        If Not objFolder Is Nothing Then
            Set objAppt = objFolder.Items.Add
            If Not objAppt Is Nothing Then
                With objAppt
                    .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                    & "          " & DisplayNameFM & "  --  " & FamilyMember
                    .Start = Me!ApptDate & " " & Me!ApptTime
                    .Duration = Me!ApptLength
                    '.AllDayEvent = True
                    If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Family Member Main Phone: " & Mp3 & "  --  " & "Family Member Cell Phone: " & Cp3
                    If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                    If Me!ApptReminder Then
                        .ReminderMinutesBeforeStart = Me!ReminderMinutes
                        .ReminderSet = True
                    End If
                    .Save
                End With
            End If
        End If
    End If ' Added
ElseIf Me.PrimaryClientName > 0 Then
    objRecip.Resolve
    If objRecip.Resolved Then
        On Error Resume Next
        Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
     
        If Not objFolder Is Nothing Then
            Set objAppt = objFolder.Items.Add
            If Not objAppt Is Nothing Then
                With objAppt
                    .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                    & "          " & DisplayNamePC & " -- " & PrimaryClientName
                    .Start = Me!ApptDate & " " & Me!ApptTime
                    .Duration = Me!ApptLength
                    '.AllDayEvent = True
                    If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                         vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Primary Client Main Phone: " & Mp2 & "  --  " & "Primary Client Cell Phone: " & Cp2
                         
                    If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                            .ReminderSet = True
                        End If
                        .Save
                    End If
                End With
            End If
        End If
    End If
 End If
 

  ' Release the Outlook object variable.
         Set outobj = Nothing
         Set objApp = Nothing
         Set objNS = Nothing
         Set objFolder = Nothing
         Set objDummy = Nothing
         Set objRecip = Nothing
         Set objAppt = Nothing
  ' Set the AddedToOutlook flag, save the record, display a message.
         Me.AddedToOutlook = True
         MsgBox "Appointment Added!"
     
 End Sub

Open in new window

Regards
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ste5anSenior DeveloperCommented:
E.g. much cleaner when refactored:

Private Sub YourCurrentMethod()

	If Me.FamilyMember > 0 Then
		Set objAppt = CreateAppointment()
		CreateFamilyAppointment objAppt
	ElseIf Me.PrimaryClientName > 0 Then
		Set objAppt = CreateAppointment()
		CreatePrimaryClient objAppt
	End If

End Sub

Private Function CreateAppointment() As Object

	objRecip.Resolve
	If objRecip.Resolved Then
		Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)	
		If Not objFolder Is Nothing Then
			Set objAppt = objFolder.Items.Add
		End If
	End If

End Function

Private Sub CreateFamilyAppointment(AAppointment As Object)
 
 	With AAppointment
		.Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
		& "          " & DisplayNameFM & "  --  " & FamilyMember
		.Start = Me!ApptDate & " " & Me!ApptTime
		.Duration = Me!ApptLength
		'.AllDayEvent = True
		If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
			vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Family Member Main Phone: " & Mp3 & "  --  " & "Family Member Cell Phone: " & Cp3
		If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
		If Me!ApptReminder Then
			.ReminderMinutesBeforeStart = Me!ReminderMinutes
			.ReminderSet = True
		End If
		.Save
	End With
	
 End Sub
 
 Private Sub CreatePrimaryClient(AAppointment As Object)
 
 	With AAppointment
		.Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
		& "          " & DisplayNamePC & " -- " & PrimaryClientName
		.Start = Me!ApptDate & " " & Me!ApptTime
		.Duration = Me!ApptLength
		'.AllDayEvent = True
		If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
			 vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Primary Client Main Phone: " & Mp2 & "  --  " & "Primary Client Cell Phone: " & Cp2
			 
		If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
			If Me!ApptReminder Then
				.ReminderMinutesBeforeStart = Me!ReminderMinutes
				.ReminderSet = True
			End If
			.Save
		End If
	End With
	
 End Sub

Open in new window

1
VGuerra67Author Commented:
Private Sub AddAppt_Click()
'On Error GoTo AddAppt_Err
    'Save record first to be sure required fields are filled.
'DoCmd.RunCommand acCmdSaveRecord
    'Exit the procedure if appointment has been added to Outlook.
If Me!AddedToOutlook = True Then
    MsgBox "This appointment already added to Microsoft Outlook"
    Exit Sub
    'Add a new appointment.
Else
    Dim objApp As Outlook.Application
    Dim objNS As Outlook.NameSpace
    Dim objFolder As Outlook.MAPIFolder
    Dim objDummy As Outlook.MailItem
    Dim objRecip As Outlook.Recipient
    Dim objAppt As Outlook.AppointmentItem
    Dim strMsg, ClientMainPhone, ClientCellPhone, ProspMainPhone, ProspCellPhone, Acct, NewBlankLine As String
    Dim strName, Mp1, Mp2, Mp3, Cp1, Cp2, Cp3 As String
    On Error Resume Next
     
    ' ### name of person whose Calendar you want to use ###
    strName = Me.CboCalName.Column(1)
    Mp1 = Nz(DLookup("PhoneNumber", "ProspectiveClients", "ProspectID =" & ProspectID_FK), "0000000000")
    Mp2 = Nz(DLookup("PhoneNumber", "ProspectiveClients", "ProspectID =" & PrimaryClientName), "0000000000")
    Mp3 = Nz(DLookup("PhoneNumber", "ProspectiveClients", "ProspectID =" & FamilyMember), "0000000000")
    Cp1 = Nz(DLookup("MobilePhone", "ProspectiveClients", "ProspectID =" & ProspectID_FK), "0000000000")
    Cp2 = Nz(DLookup("MobilePhone", "ProspectiveClients", "ProspectID =" & PrimaryClientName), "0000000000")
    Cp3 = Nz(DLookup("MobilePhone", "ProspectiveClients", "ProspectID =" & FamilyMember), "0000000000")
    Me!RIGEmp = Environ("USERNAME")
    Me!RIGSetDate = Now()
    
     
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    Set objDummy = objApp.CreateItem(olMailItem)
    Set objRecip = objDummy.Recipients.Add(strName)
    NewBlankLine = ""
    
If Me.FamilyMember > 0 Then
        objRecip.Resolve
            If objRecip.Resolved Then
            On Error Resume Next
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
            
                If Not objFolder Is Nothing Then
                    Set objAppt = objFolder.Items.Add
                        If Not objAppt Is Nothing Then
                            With objAppt
                                .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                                & "          " & DisplayNameFM & "  --  " & FamilyMember
                                .Start = Me!ApptDate & " " & Me!ApptTime
                                .Duration = Me!ApptLength
                                '.AllDayEvent = True
                        If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Family Member Main Phone: " & Mp3 & "  --  " & "Family Member Cell Phone: " & Cp3
                        If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                             .ReminderSet = True
                        End If
                            .Save
                            End With
                        End If
                        End If
                Else
                MsgBox "Could not find " & Chr(34) & strName & Chr(34), , _
               "User not found"
               
If Me.PrimaryClientName > 0 Then
        objRecip.Resolve
            If objRecip.Resolved Then
            On Error Resume Next
            Set objFolder = objNS.GetSharedDefaultFolder(objRecip, olFolderCalendar)
            
                If Not objFolder Is Nothing Then
                    Set objAppt = objFolder.Items.Add
                        If Not objAppt Is Nothing Then
                            With objAppt
                                .Subject = Me!Appt.Column(1) & "  --  " & DisplayName & "  --  " & Forms!MainProspectFrm!ProspectID _
                                & "          " & DisplayNamePC & " -- " & PrimaryClientName
                                .Start = Me!ApptDate & " " & Me!ApptTime
                                .Duration = Me!ApptLength
                                '.AllDayEvent = True
                        If Not IsNull(Me!ApptNotes) Then .Body = "Appointment Set By -- " & Me.RIGEmp & "  On   " & Me.RIGSetDate & vbCrLf & "APPOINTMENT NOTES: " & vbCrLf & Me!ApptNotes & vbCrLf & vbCrLf & _
                        vbCrLf & "Prospect Client Main Phone: " & Mp1 & "  --  " & "Prospect Client Cell Phone: " & Cp1 & vbCrLf & vbCrLf & "Primary Client Main Phone: " & Mp2 & "  --  " & "Primary Client Cell Phone: " & Cp2
                        
                        If Not IsNull(Me!ApptLocation) Then .Location = Me!ApptLocation.Column(1)
                        If Me!ApptReminder Then
                            .ReminderMinutesBeforeStart = Me!ReminderMinutes
                             .ReminderSet = True
                        End If
                            .Save
                            End With
                        End If
                        End If
                Else
                MsgBox "Could not find " & Chr(34) & strName & Chr(34), , _
               "User not found"
End If
End If
End If
End If
End If

 ' Release the Outlook object variable.
        Set outobj = Nothing
        Set objApp = Nothing
        Set objNS = Nothing
        Set objFolder = Nothing
        Set objDummy = Nothing
        Set objRecip = Nothing
        Set objAppt = Nothing
 ' Set the AddedToOutlook flag, save the record, display a message.
        Me.AddedToOutlook = True
        MsgBox "Appointment Added!"
    
End Sub

Open in new window

0
VGuerra67Author Commented:
Sorry this is the entire code.  I tried ste5an solution but its not creating the appointment
0
Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
after the first if statement it does not go to the elseif.
It would go through the ElseIf block only when the line below evaluates to True:

Me.PrimaryClientName > 0

Based solely on the name, I'd think that PrimaryClientName is a String value, and therefore comparing it to 0 will give you odd results. If you want to know if there is a value in PrimaryClientName, then check the Len value:

ElseIf Len(Me.PrimaryClientName) > 0 Then

If that value can be null, also use the Nz function:

ElseIf Len(Nz(Me.PrimaryClientName,"")) > 0 Then
2
sarabandeCommented:
after the first if statement it does not go to the elseif..
beside of the remarks Scott has made, you may consider that the elseif only would be checked if

Me.FamilyMember > 0

was false. i can't see any in your code which would change that attribute. therefore it is unlikely that after once performing the if block it ever would perform the alternative elseif block.

Sara
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.