I may missing the obvious but I can't seem to figure out what it is.
My code works fine in updating Outlook but after it has 'finished' running and I go back to VBA there is a "Run-time error '13': Type mismatch." Highlighting the line
comp is a check box which if set to true I want the appointment to have "complete" added to the subject. That is working fine.
I have tried to find out if the Dim statement is incorrect to cause the error but no luck.
Here is the whole code...in case that makes my mud seem clearer...
Any help and suggestions are greatly appreciated.
My code works fine in updating Outlook but after it has 'finished' running and I go back to VBA there is a "Run-time error '13': Type mismatch." Highlighting the line
Code:
Set comp = Me.Controls(Choose(i, "tMade", "tTopCut", "tBowlCut", "tAssembled", "tGluedTop", "tPolished", _
"tInstalled", "tGluedSink", "tPainted", "tDelivered"))
comp is a check box which if set to true I want the appointment to have "complete" added to the subject. That is working fine.
I have tried to find out if the Dim statement is incorrect to cause the error but no luck.
Code:
Dim comp As Control
Here is the whole code...in case that makes my mud seem clearer...
Code:
Private Sub cmdComplete_Click()
Me.Dirty = False
If Me.chkAddedtoOutlook = True Then
MsgBox "This appointment has already been added to Microsoft Outlook", vbCritical
' Exit the procedure
Exit Sub
Else
' Add a new appointment.
' Use late binding to avoid the "Reference" issue
Dim olapp As Object ' Outlook.Application
Dim olappt As Object ' olAppointmentItem
Dim i As Integer
Dim ctl As Control
Dim cat As Control
Dim olfolder As Object
Dim stg As Control
Dim st As Control
Dim et As Control
Dim comp As Control
If isAppThere("Outlook.Application") = False Then
' Outlook is not open, create a new instance
Set olapp = CreateObject("Outlook.Application")
Else
' Outlook is already open--use this method
Set olapp = GetObject(, "Outlook.Application")
End If
Set olfolder = olapp.GetNamespace("mapi").PickFolder
For i = 1 To 11
Set olappt = olfolder.Items.Add ' olAppointmentItem
Set ctl = Me.Controls(Choose(i, "DateTemplateMade", "DateofTopCut", "DateBowlCut", "dateassembletop", _
"DateGlueTop", "DatePolishTop", "dateinstallpackers", "dategluesink", "datepaint", "datequalitycheck", _
"deliveryinstalled"))
Set cat = Me.Controls(Choose(i, "Templatemade", "TopCut", "BowlCut", "AssembleTop", "GlueTop", _
"PolishTop", "InstallPackers", "Gluesink", "Paint", "Qualitycheck", "DeliveryInstall"))
Set stg = Me.Controls(Choose(i, "Templatemade", "TopCut", "BowlCut", "AssembleTop", "GlueTop", _
"PolishTop", "InstallPackers", "Gluesink", "Paint", "Qualitycheck", "DeliveryInstall"))
Set st = Me.Controls(Choose(i, "sttm", "sttc", "stbc", "stat", "stgt", "stpt", "stip", "stgs", "stp", _
"stqc", "stdi"))
Set et = Me.Controls(Choose(i, "ettm", "ettc", "etbc", "etat", "etgt", "etpt", "etip", "etgs", "etp", _
"etqc", "etdi"))
Set comp = Me.Controls(Choose(i, "tMade", "tTopCut", "tBowlCut", "tAssembled", "tGluedTop", "tPolished", _
"tInstalled", "tGluedSink", "tPainted", "tDelivered"))
Rem check value of current control
If Not Nz(ctl, "") = "" And Nz(comp, "") = True Then
Rem control is neither Null nor empty string - create appointment
Start = ctl
With olappt
' If There is no Start Date or Time on
' the Form use Nz to avoid an error
' Set the Start Property Value
.Start = Nz(ctl, "") & " " & Nz(st, "")
' Set the End Property Value
.End = Nz(ctl, "") & " " & Nz(et, "")
.Subject = Nz("Complete" & stg & " " & Me.JobName, vbNullString)
.Mileage = Nz(Me.QuoteNo, vbNullString)
.Location = Nz(Me.InstallAddress & ", " & Me.InstallAddress2 & ", " & Me.Town_City)
.Body = Nz(Me.Notes, vbNullString)
.Categories = cat
.Save
End With
End If
Next
End If ' Release the Outlook object variables.
Set olappt = Nothing
Set olapp = Nothing ' Set chkAddedToOutlook to checked
Me.chkAddedtoOutlook = True
' Save the Current Record because we checked chkAddedToOutlook
Me.Dirty = False
' Inform the user
MsgBox "Appointment Added!", vbInformation
End Sub
Any help and suggestions are greatly appreciated.