VBA If else problem

Elmobram22

Registered User.
Local time
Today, 01:53
Joined
Jul 12, 2013
Messages
165
Hi all,

I have a button on a form and I want it to do two things based on whether a field is blank or not. I am getting errors and can't seem to sort it. I have attached the code. Thanks in advance...

Private Sub Command15_Click()
If Me!ProposedProbationPeriod = Null Then
Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.Start = Date + 7 & " " & Me!InsApptTime
.Duration = 15
.Subject = Me!FirstName & " " & LastName & " has no probation period end date"
.Body = Me!FirstName & " " & LastName & " has no probation period end date"
.Location = "None"
.ReminderMinutesBeforeStart = 15
.ReminderSet = True
.Save
DoCmd.OpenForm "FrmPrevTrainingRec", , , "StaffID = " & Me!StaffID
Forms("Frm3").SetFocus
DoCmd.Close
Else
If Me!ProposedProbationPeriod = Not Null Then
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.Start = Me!ProposedProbationPeriod & " " & Me!InsApptTime
.Duration = 15
.Subject = Me!FirstName & " " & LastName & " probation period ends today"
.Body = Me!FirstName & " " & LastName & " probation period ends today"
.Location = "None"
.ReminderMinutesBeforeStart = 15
.ReminderSet = True
.Save
End If
Set outobj = Nothing
DoCmd.OpenForm "FrmPrevTrainingRec", , , "StaffID = " & Me!StaffID
Forms("Frm3").SetFocus
DoCmd.Close
End Sub
 
it would help if you used the code tags and indent your code - it is very difficult to read to the uninitiated

you say you get errors - what errors and what row of the code does it occur
 
Here's a screen shot
 

Attachments

  • d1.png
    d1.png
    60.6 KB · Views: 122
I think you need to put 'End With' after the end of your 'With' statements.
 

Users who are viewing this thread

Back
Top Bottom