Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 27th, 2015, 10:42 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Feb 2013
Location: Toronto, Canada
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Trying to Create Appointment in Outlook from Access

I have an Access database for my contracting business. On the main form, it contains all of the relevant information about the client (name, address, service date, etc.). On the main form, I have a subform which contains multiple records, listing each item of work to be done in the client's home (one record for each item of work to be done).

I have written the code in the OnClick event of a command button to create the Appointment in my Outlook Calendar, and in the notes section of the appointment, I want all of the records from the subform showing the work to be done. When I execute the code, I get an error message of "Too few parameters. Expected 2." The code is below:

Private Sub btnCreateAppointment_Click()
On Error GoTo Err_btnCreateAppointment_Click

    'First Save the Current Record
    DoCmd.RunCommand acCmdSaveRecord
    'Exit the procedure if the appointment has already been added to the Outlook Calendar
    If Me.ApptAddedtoOutlook = True Then
        MsgBox "This appointment has already been added to the Outlook Calendar.", vbOKOnly, "Crate & Pack"
        Exit Sub
        Dim olObj As Outlook.Application
        Dim olAppt As Outlook.AppointmentItem
        Dim strLocation As String
        Dim strContact As String
        Dim strSQL As String
        Dim db As DAO.Database
        Dim rst As DAO.Recordset
        Set olObj = CreateObject("Outlook.Application")
        Set olAppt = olObj.CreateItem(olAppointmentItem)
        If Not IsNull(Me.ClientAptNumber) Then
            strLocation = (Me.ClientAptNumber & " - " & Me.ClientStreetAddress & ", " & Me.ClientCityName & ", " & Me.ClientState & "  " & Me.ClientZipCode)
            strLocation = (Me.ClientStreetAddress & ", " & Me.ClientCityName & ", " & Me.ClientState & "  " & Me.ClientZipCode)
        End If
        If Not IsNull(Me.ClientPhone2) Then
            strContact = (Me.ClientPhone1 & " " & Me.ClientPhoneType1 & "  " & Me.ClientPhone2 & " " & Me.ClientPhoneType2)
            strContact = (Me.ClientPhone1 & " " & Me.ClientPhoneType1)
        End If
        strSQL = "SELECT tblOrderDetails.Quantity, tblOrderDetails.ServiceType, tblOrderDetails.ServiceDetails " & _
                "FROM tblOrders INNER JOIN tblOrderDetails ON tblOrders.OrderNumber = tblOrderDetails.OrderNumber " & _
                "WHERE tblOrderDetails.ServiceType <> ""Trip Charge"" Or tblOrderDetails.ServiceType <> ""Tax Exempt"" " & _
                "And tblOrderDetails.OrderNumber = " & [Forms]![frmOrders]![OrderNumber] & " " & _
                "ORDER BY tblOrderDetails.ServiceType"
        Set db = CurrentDb()
        Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
        With rst
            Do Until rst.EOF
            strSQL = rst.Fields("Quantity") & vbTab & _
            rst.Fields("ServiceType") & " - " & _
            rst.Fields("ServiceDetails") & vbCrLf
            DoCmd.SendObject acSendNoObject, , , , , , strSQL, , False, False
        End With
    With olAppt
        .Start = Me.ServiceDate & " " & Me.ApptTime
        .Duration = Me.ApptDuration
        .Subject = (Me.CustNumber & " - Service Appointment - " & Me.OrderNumber & "    " & Me.ClientUserlastName & ", " & Me.ClientUserFirstName)
        .Location = strLocation & "   " & strContact
        If Me.ApptReminder = True Then
        .ReminderSet = True
        .ReminderMinutesBeforeStart = Me.ReminderMinutes
        End If
        .RequiredAttendees = "myemail"
        .Body = strSQL
    End With
    End If
        'Release the Outlook object variables
        Set olObj = Nothing
        Set olAppt = Nothing
        Set rst = Nothing
        Set db = Nothing
        'Set the Added to Outlook flag, save the record, and display a message
        Me.ApptAddedtoOutlook = True
        DoCmd.RunCommand acCmdSaveRecord
        MsgBox "Appointment Added", vbOKOnly, "Crate & Pack"
    Exit Sub
    Exit Sub
    MsgBox Err.Description, vbOKOnly, "Crate & Pack"
    Resume Exit_btnCreateAppointment_Click
End Sub
With the main form open, when I run the SQL query, it works perfectly, giving me all the records for that specific client. But when I execute the code to add the appointment, I get the error message.

I have searched several forums for help but so far no luck. Could someone please point me in the right direction? I would appreciate any help I can get.

Waynes World
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't save outlook appointment user properties pannasn WinForms/Console Application Design 2 March 3rd, 2010 11:46 AM
how to create outlook plug in vikki227 PHP How-To 0 December 2nd, 2009 09:00 AM
modify create appointment wizard jeanhl BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 March 24th, 2008 03:37 AM
outlook style appointment control help, thanks! raybristol C# 0 January 17th, 2006 11:39 PM
automate access date to outlook appointment serverrunner Access 2 August 2nd, 2004 08:15 PM

All times are GMT -4. The time now is 06:54 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.