Hi there, This is the complete code i have presently on my subform:
Option Compare Database
Dim cboOriginator As ComboBox
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.
Else
Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.Start = Me!Threemonthappointment & " " & Me!ApptTime
.Duration = Me!ApptLength
.Subject = Me!SSN
.Save
End With
End If
' Release the Outlook object variable.
Set outobj = Nothing
' Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
Exit Sub
AddAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
Private Sub AddAppt1_Click()
On Error GoTo AddAppt1_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!AddedToOutlook1 = True Then
MsgBox "This appointment already added to Microsoft Outlook"
Exit Sub
' Add a new appointment.
Else
Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("outlook.application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.Start = Me!Ninemonthappointment & " " & Me!ApptTime1
.Duration = Me!ApptLength1
.Subject = Me!SSN
.Save
End With
End If
' Release the Outlook object variable.
Set outobj = Nothing
' Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook1 = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
Exit Sub
AddAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub
Private Sub DateEnrolled_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = DateEnrolled
' Unhide the calendar and give it the focus
Calendar4.Visible = True
Calendar4.SetFocus
' Match calendar date to existing date if present or today's date
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub Date_of_call_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = Date_of_call
' Unhide the calendar and give it the focus
Calendar4.Visible = True
Calendar4.SetFocus
' Match calendar date to existing date if present or today's date
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub Form_Load()
Me.Calendar4.Today
End Sub
Private Sub Calendar4_Click()
cboOriginator.Value = Calendar4.Value
' Return the focus to the combo box and hide the calendar and
cboOriginator.SetFocus
Calendar4.Visible = False
' Empty the variable
Set cboOriginator = Nothing
End Sub
Private Sub Date_of_call_at_9_month_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = Date_of_call_at_9_month
' Unhide the calendar and give it the focus
Calendar4.Visible = True
Calendar4.SetFocus
' Match calendar date to existing date if present or today's date
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub Date_of_f_u_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = Date_of_f_u
' Unhide the calendar and give it the focus
Calendar4.Visible = True
Calendar4.SetFocus
' Match calendar date to existing date if present or today's date
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Private Sub Date_of_last_attempt_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Set cboOriginator = Date_of_last_attempt
' Unhide the calendar and give it the focus
Calendar4.Visible = True
Calendar4.SetFocus
' Match calendar date to existing date if present or today's date
If Not IsNull(cboOriginator) Then
Calendar4.Value = cboOriginator.Value
Else
Calendar4.Value = Date
End If
End Sub
Now i have 2 command buttons with each for their respective appointment to be added to outlook.
Again I tried making up another table and form and put it on the demographics form and then used the
=[Forms]![Demographics]!
.[Form]![DateEnrolled]+270 for ninemonthappointment and it worked again but not a good way to work it out. I have since reverted back to my original two forms only.
i haven't tried Tom's last suggestion yet but if you could let meknow where to insert the code in the above code would help, or if you guys can think any other modification to the issue may also help.
thanks