Hi,
I have a form which is used to give appointments. I need these appointments to show up in outlook calendar. I have successed partially by using following vba code in public function and then calling on this function in the VBA code of the form:
Since this doesnt work if outlook in not open, I have following code to open outlook if not already open:
This saves the appointments under calender folder in outlook. However I need for these to be saved under another calender (named "Private") which I have created as a subfolder of the main calendar folder.
Despite trying different things I have been unable to achieve this. Any ideas on how this can be achieved?
Thanks in advance
I have a form which is used to give appointments. I need these appointments to show up in outlook calendar. I have successed partially by using following vba code in public function and then calling on this function in the VBA code of the form:
Code:
Public Function AddAppointment(ByVal BD As Date, ByVal Endo As String, ByVal Pt As String, ByVal Hos As String, ByVal CN As Long) As Boolean
Dim Ol As Outlook.Application
Dim appt As Outlook.AppointmentItem
Set Ol = New Outlook.Application
Set appt = Ol.CreateItem(olAppointmentItem)
With appt
.Start = BD
.Duration = 0
.Subject = Endo
.Location = Hos
.Body = Pt & " " & CN
.ReminderSet = False
.Save
End With
Set appt = Nothing
Set Ol = Nothing
AddAppointment = True
End Function
Since this doesnt work if outlook in not open, I have following code to open outlook if not already open:
Code:
Private Sub fireOutlook()
Dim olShellVal As Long
Dim g_olApp As Object
On Error GoTo FIREOUTLOOK_ERR
Set g_olApp = GetObject(, "Outlook.Application")
If g_olApp Is Nothing Then
olShellVal = Shell("OUTLOOK", vbNormalNoFocus)
Set g_olApp = CreateObject("Outlook.Application")
g_olApp.ActiveExplorer.WindowState = 1
End If
FIREOUTLOOK_EXIT:
Exit Sub
FIREOUTLOOK_ERR:
If g_olApp Is Nothing Then
Err.Clear
Resume Next
Else
MsgBox Err.Description, , "Error Number: " & Err.Number
End If
GoTo FIREOUTLOOK_EXIT
End Sub
This saves the appointments under calender folder in outlook. However I need for these to be saved under another calender (named "Private") which I have created as a subfolder of the main calendar folder.
Despite trying different things I have been unable to achieve this. Any ideas on how this can be achieved?
Thanks in advance