[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 256
  • Last Modified:

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

0
bearsgone
Asked:
bearsgone
  • 5
1 Solution
 
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
Free tool for managing users' photos in Office 365

Easily upload multiple users’ photos to Office 365. Manage them with an intuitive GUI and use handy built-in cropping and resizing options. Link photos with users based on Azure AD attributes. Free tool!

 
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

Featured Post

Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now