Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2004

    Red face Unanswered: "Object variable or with block variable not set

    This is some code to allow a meeting request be sent from within an Access database.
    The first section up to "##########' works fine and it will be added to your own calendar (based on a form and table elsewhere in the DB.)

    Why is it that my code shown here constantly comes up with "object variable or with block variable not set" I think it is because I need to declare a set of oRecipt just under the Dim oRecipt as Outlook.Recipient
    but I can't seem to format it without type mismatchs, etc.
    the original code for this came from Microsoft Q313789 but this is based around building an actual VB app, as opposed to VB code within Access. I basically need to conversion. Any ideas?...or does anyone know of snippet of code available to integrate into Access that will do what I want...i.e creating meeting requests from within access for clients/employees within the database.

    Option Compare Database

    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.
    Dim oApp As Outlook.Application
    Dim oAppt As Outlook.AppointmentItem
    Set oApp = CreateObject("outlook.application")
    Set oAppt = oApp.CreateItem(olAppointmentItem)
    With oAppt
    .MeetingStatus = olMeeting
    .Subject = Me!Appt
    .Start = Me!Apptdate & " " & Me!Appttime
    .End = Me!Apptdatef & " " & Me!Appttimef
    'oAppt.Duration = Me!Apptlength
    If Not IsNull(Me!ApptNotes) Then .Body = Me!ApptNotes
    If Not IsNull(Me!ApptLocation) Then .Location = _
    If Me!ApptReminder Then
    .ReminderMinutesBeforeStart = Me!ReminderMinutes
    .ReminderSet = True
    End If

    .BusyStatus = olBusy
    .IsOnlineMeeting = False
    .AllDayEvent = False
    End With
    End If
    ' Add attendees.
    Dim oRecipts As Outlook.Recipients
    Set oRecipts = oAppt.Recipients
    ' Add required attendee.
    Dim oRecipt As Outlook.Recipient
    oRecipt = oRecipts.Add("Test user1") ' TODO:
    oRecipt.Type = Outlook.OlMeetingRecipientType.olRequired

    ' Add optional attendee.
    oRecipt = oRecipts.Add("Test User2") ' TODO:
    oRecipt.Type = Outlook.OlMeetingRecipientType.olOptional

    ' resolve names


    ' Send out request.

    ' Release the Outlook object variable.
    Set oAppt = Nothing
    ' Set the AddedToOutlook flag, save the record, display a message.
    Me!AddedToOutlook = True
    DoCmd.RunCommand acCmdSaveRecord
    MsgBox "Appointment Added!"
    Exit Sub
    MsgBox "Error " & Err.Number & vbCrLf & Err.Description
    Exit Sub

    End Sub

  2. #2
    Join Date
    Jan 2004
    replace the line in your code

    oRecipt = oRecipts.Add("Test user1")


    Set oRecipt = oRecipts.Add("Test user1")

    Should work fine then.

Posting Permissions

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