Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 27th, 2015, 10:42 PM
Registered User
 
Join Date: Feb 2013
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:

Code:
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
    Else
        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)
        Else
            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)
        Else
            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
            .MoveFirst
            Do Until rst.EOF
            strSQL = rst.Fields("Quantity") & vbTab & _
            rst.Fields("ServiceType") & " - " & _
            rst.Fields("ServiceDetails") & vbCrLf
            DoCmd.SendObject acSendNoObject, , , , , , strSQL, , False, False
            .MoveNext
            Loop
        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
        .Save
        
    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_btnCreateAppointment_Click:
    Exit Sub
    
Err_btnCreateAppointment_Click:
    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





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





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