VBA If else problem

mardi 3 mars 2015

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

VBA If else problem

0 commentaires:

Enregistrer un commentaire

Labels