Link to home
Start Free TrialLog in
Avatar of bearsgone
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.ActiveInspector 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.ActiveInspector.CurrentItem

If Appt.MessageClass = "IPM.Appointment.Tim3.18.2010" Then
Set ctrl = Application.ActiveInspector.ModifiedFormPages("Transportation_Form").Controls("PatientPhone")
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

Avatar of Helen Feddema
Helen Feddema
Flag of United States of America image

What is the purpose of the line
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):

Set ups = itm.UserProperties
'Get value of custom property
strCustom = ups("CustomProperty")

Open in new window

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

Open in new window

Also, though no doubt this is because the code is still in the testing stage, you have some redundant variables.
ASKER CERTIFIED SOLUTION
Avatar of bearsgone
bearsgone

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial