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

bearsgoneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Helen FeddemaCommented:
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

0
Helen FeddemaCommented:
Use the name of the custom property, which may be different than the control name.
0
Helen FeddemaCommented:
And make sure that the custom property and the variable set from it are of the same data type.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Helen FeddemaCommented:
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

0
Helen FeddemaCommented:
Also, though no doubt this is because the code is still in the testing stage, you have some redundant variables.
0
bearsgoneAuthor Commented:
Thank you for feedback. No w I am getting error 424, looks like it ca not find field?. Under Field and Format of Control I have PatientPhone I assume it is a control name, in advanced properties for the field I have "phone" which I assume is the name of the property not control. I tried both with same 424 error.

Here is modified version:
Sub FormtoAppt()
Dim line1 As Object
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


COMMENTED OUT 'Set ctrl = Application.ActiveInspector.ModifiedFormPages("Transportation_Form").Controls("PatientPhone")


Set ups = objCurrentAppt.UserProperties
strCustom = ups("phone")
line1 = strCustom
objAppt.Body = line1
objAppt.Display
Else
MsgBox "Error:Custom Appointment is not open!"
GoTo ErrorCode
End If
Exit Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.