bearsgone
asked on
Copying data between tabs in a custom form
I have custom form that is appointment with a second tab called: Transportation Form. I am trying to copy a field from custom form to appointment body. I am getting an error -2147024809 right after Set ctrl = Application.ActiveInspecto r line. not sure what the problem is
Sub FormtoAppt()
Dim line1 As String
Dim objCurContact As ContactItem
Dim objAppt As AppointmentItem
Dim ctrl As Object
Dim Appt As Outlook.AppointmentItem
On Error GoTo ErrorCode
Set Appt = Application.ActiveInspecto r.CurrentI tem
If Appt.MessageClass = "IPM.Appointment.Tim3.18.2 010" Then
Set ctrl = Application.ActiveInspecto r.Modified FormPages( "Transport ation_Form ").Control s("Patient Phone")
line1 = ctrl
objAppt.Body = txtBody1
objAppt.Display
Else
MsgBox "Error:Custom Appointment is not open!"
GoTo ErrorCode
End If
Exit Sub
ErrorCode:
If Err.Number = 91 Then
MsgBox Prompt:="Custom App mus be open!", Buttons:=vbCritical, Title:="App Error"
Else
MsgBox Prompt:="Appt Macro raised an Error!", Buttons:=vbExclamation, Title:="Appt"
End If
End Sub
Sub FormtoAppt()
Dim line1 As String
Dim objCurContact As ContactItem
Dim objAppt As AppointmentItem
Dim ctrl As Object
Dim Appt As Outlook.AppointmentItem
On Error GoTo ErrorCode
Set Appt = Application.ActiveInspecto
If Appt.MessageClass = "IPM.Appointment.Tim3.18.2
Set ctrl = Application.ActiveInspecto
line1 = ctrl
objAppt.Body = txtBody1
objAppt.Display
Else
MsgBox "Error:Custom Appointment is not open!"
GoTo ErrorCode
End If
Exit Sub
ErrorCode:
If Err.Number = 91 Then
MsgBox Prompt:="Custom App mus be open!", Buttons:=vbCritical, Title:="App Error"
Else
MsgBox Prompt:="Appt Macro raised an Error!", Buttons:=vbExclamation, Title:="Appt"
End If
End Sub
Use the name of the custom property, which may be different than the control name.
And make sure that the custom property and the variable set from it are of the same data type.
If you need to pick up a change in a custom property immediately, here is some typical code for that event:
Sub Item_CustomPropertyChange(ByVal strName)
Select Case strName
Case "ProgramName"
Item.BillingInformation = Item.UserProperties("ProgramName") _
& Item.UserProperties("StationOrNetwork")
Case "StationOrNetwork"
Item.BillingInformation = Item.UserProperties("ProgramName") _
& Item.UserProperties("StationOrNetwork")
Case "Call"
Call HandleCall()
Case "InterviewStatus"
Call HandleInterview()
Case "TimeZoneOK"
If Item.UserProperties("TimeZoneOK") = True Then
Call GuestTimeStart()
Call GuestTimeEnd()
End If
Case "StationTimeZone"
If Left(strStationTimeZone, 7) = "[Select" Then
Exit Sub
Else
Call GuestTimeStart()
Call GuestTimeEnd()
End If
Case "GuestTimeZone"
If Left(strGuestTimeZone , 7) = "[Select" Then
Exit Sub
Else
Call GuestTimeStart()
Call GuestTimeEnd()
End If
End Select
End Sub
Also, though no doubt this is because the code is still in the testing stage, you have some redundant variables.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
line1 = ctrl?
As it, it won't work, because you are setting a String variable to a Control object.
Apart from that, it may be better to pick up the value of the custom property directly, rather than going through a control. Here is code to work with an Outlook custom property (for your code, I think you could use objCurrentAppt where I have itm):
Open in new window