A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Macro to populate contact fields no longer working



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 27th 07, 05:35 PM posted to microsoft.public.outlook.program_vba
RitaP
external usenet poster
 
Posts: 2
Default Macro to populate contact fields no longer working

Amateur using VBA. I copied and customized this macro a while ago and it
worked until I upgraded to Outlook 2007. What I'm doing is populating contact
fields, name, address, phone, email address from an email that contains info
in the body. The macro still creates a contact and puts it in correct contact
folder but the fields are no longer populated with info. The info I input is
being put correctly into notes section.

I haven't had time to dig in to this. Wonder if anyone can help since I
don't have new books on Outlook 2007 vba to help me. Thanks.
Rita

Macro

Sub WebContactCreateV3()

Dim objApp As Application
Dim objNS As NameSpace
Dim ContactsFolder As MAPIFolder
Dim TargetFolder As Outlook.MAPIFolder
Dim oInspector As Inspector
Dim objItem As Object
Dim objCurItem As Object
Dim strBody As String
Dim strCustnum, strSalePer, strLimits As String
Dim objContact As ContactItem
Dim strFirstName As String
Dim strLastName As String
Dim strFileAs As String
Dim strCompany As String


strCustnum = InputBox("Customer Number")
strSalePer = InputBox("Salesperson")
strLimits = InputBox("Limits")

Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
Set oInspector = objApp.ActiveInspector
Set objItem = oInspector.CurrentItem

If oInspector Is Nothing Then
objNS.GetDefaultFolder(olFolderInbox).Items.GetFir st.Display
Set oInspector = objApp.ActiveInspector
End If

oInspector.Activate
Select Case oInspector.EditorType
Case olEditorText
BlnIsHTML = False
strBody = objItem.Body
X = InStr(1, strBody, "Name:")
Y = InStr(1, strBody, "Title:")
A = X + 6
B = Y - A
FullName = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Company:")
A = X + 7
B = Y - A
JobTitle = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Address 1:")
A = X + 9
B = Y - A
Company = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Address 2:")
A = X + 11
B = Y - A
Address1 = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "City:")
A = X + 11
B = Y - A
Address2 = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "State:")
A = X + 6
B = Y - A
City = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Zipcode:")
A = X + 7
B = Y - A
State = UCase(Mid(strBody, A, B))
X = Y
Y = InStr(1, strBody, "Phone:")
A = X + 9
B = Y - A
Zipcode = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Fax:")
A = X + 7
B = Y - A
Phone = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Email:")
A = X + 5
B = Y - A
Fax = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "SAL B")
A = X + 7
B = Y - A
Cemail = Mid(strBody, A, B)
End Select
Set objItem = objApp.ActiveExplorer.Selection.Item(1)
Set objContact = objApp.CreateItem(olContactItem)
objContact.FullName = FullName
objContact.JobTitle = JobTitle
objContact.CompanyName = Company
objContact.BusinessAddressStreet = Address1 & Address2
objContact.BusinessAddressCity = City
objContact.BusinessAddressState = State
objContact.BusinessAddressPostalCode = Zipcode
objContact.BusinessTelephoneNumber = Phone
objContact.BusinessFaxNumber = Fax
objContact.Email1Address = Cemail
objContact.Body = "Cust # " & strCustnum & vbCrLf & "Salesperson: "
& strSalePer & vbCrLf & "Limits: " & strLimits & strBody
objContact.Categories = "Web Customer"
With objContact
strCompany = .CompanyName
strFirstName = .FirstName
strLastName = .LastName
strFileAs = strCompany & " (" & strLastName & ", " &
strFirstName & ")"
.FileAs = strFileAs
.Display

End With

objContact.Save

Set objCurItem = Application.ActiveInspector.CurrentItem
Set ContactsFolder =
Application.Session.GetDefaultFolder(olFolderConta cts)
Set TargetFolder = ContactsFolder.Folders("Web Customers")
Set objCurItem = objCurItem.Move(TargetFolder)

End Sub

What Subject field of email looks like: 2 blank lines then

Account: username
Password: abcdefg
Name: John Doe
Title: Operations Manager
Company: XYZ, Inc.
Address 1: 343 Smith Avenue
Address 2:
City: Anycity
State: PA
Zipcode: 12345
Phone: 555-123-4567
Fax:
Email:
SAL Branch: Crafton
SAL Primary Order Dept: Equipment
View AR: No
View Orders: Yes
View Invoices: Yes
View Items: Yes
Enter Orders: Yes
Change Password: Yes




Ads
  #2  
Old February 27th 07, 06:20 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Macro to populate contact fields no longer working

I suspect that if you stepped through the code -- an essential basic troubleshooting step -- you'd find that EditorType is not olEditorText. You can probably take out the Select Case, Case, and End Select statements and have the code work fine.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"RitaP" wrote in message ...
Amateur using VBA. I copied and customized this macro a while ago and it
worked until I upgraded to Outlook 2007. What I'm doing is populating contact
fields, name, address, phone, email address from an email that contains info
in the body. The macro still creates a contact and puts it in correct contact
folder but the fields are no longer populated with info. The info I input is
being put correctly into notes section.

I haven't had time to dig in to this. Wonder if anyone can help since I
don't have new books on Outlook 2007 vba to help me. Thanks.
Rita

Macro

Sub WebContactCreateV3()

Dim objApp As Application
Dim objNS As NameSpace
Dim ContactsFolder As MAPIFolder
Dim TargetFolder As Outlook.MAPIFolder
Dim oInspector As Inspector
Dim objItem As Object
Dim objCurItem As Object
Dim strBody As String
Dim strCustnum, strSalePer, strLimits As String
Dim objContact As ContactItem
Dim strFirstName As String
Dim strLastName As String
Dim strFileAs As String
Dim strCompany As String


strCustnum = InputBox("Customer Number")
strSalePer = InputBox("Salesperson")
strLimits = InputBox("Limits")

Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
Set oInspector = objApp.ActiveInspector
Set objItem = oInspector.CurrentItem

If oInspector Is Nothing Then
objNS.GetDefaultFolder(olFolderInbox).Items.GetFir st.Display
Set oInspector = objApp.ActiveInspector
End If

oInspector.Activate
Select Case oInspector.EditorType
Case olEditorText
BlnIsHTML = False
strBody = objItem.Body
X = InStr(1, strBody, "Name:")
Y = InStr(1, strBody, "Title:")
A = X + 6
B = Y - A
FullName = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Company:")
A = X + 7
B = Y - A
JobTitle = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Address 1:")
A = X + 9
B = Y - A
Company = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Address 2:")
A = X + 11
B = Y - A
Address1 = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "City:")
A = X + 11
B = Y - A
Address2 = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "State:")
A = X + 6
B = Y - A
City = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Zipcode:")
A = X + 7
B = Y - A
State = UCase(Mid(strBody, A, B))
X = Y
Y = InStr(1, strBody, "Phone:")
A = X + 9
B = Y - A
Zipcode = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Fax:")
A = X + 7
B = Y - A
Phone = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Email:")
A = X + 5
B = Y - A
Fax = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "SAL B")
A = X + 7
B = Y - A
Cemail = Mid(strBody, A, B)
End Select
Set objItem = objApp.ActiveExplorer.Selection.Item(1)
Set objContact = objApp.CreateItem(olContactItem)
objContact.FullName = FullName
objContact.JobTitle = JobTitle
objContact.CompanyName = Company
objContact.BusinessAddressStreet = Address1 & Address2
objContact.BusinessAddressCity = City
objContact.BusinessAddressState = State
objContact.BusinessAddressPostalCode = Zipcode
objContact.BusinessTelephoneNumber = Phone
objContact.BusinessFaxNumber = Fax
objContact.Email1Address = Cemail
objContact.Body = "Cust # " & strCustnum & vbCrLf & "Salesperson: "
& strSalePer & vbCrLf & "Limits: " & strLimits & strBody
objContact.Categories = "Web Customer"
With objContact
strCompany = .CompanyName
strFirstName = .FirstName
strLastName = .LastName
strFileAs = strCompany & " (" & strLastName & ", " &
strFirstName & ")"
.FileAs = strFileAs
.Display

End With

objContact.Save

Set objCurItem = Application.ActiveInspector.CurrentItem
Set ContactsFolder =
Application.Session.GetDefaultFolder(olFolderConta cts)
Set TargetFolder = ContactsFolder.Folders("Web Customers")
Set objCurItem = objCurItem.Move(TargetFolder)

End Sub

What Subject field of email looks like: 2 blank lines then

Account: username
Password: abcdefg
Name: John Doe
Title: Operations Manager
Company: XYZ, Inc.
Address 1: 343 Smith Avenue
Address 2:
City: Anycity
State: PA
Zipcode: 12345
Phone: 555-123-4567
Fax:
Email:
SAL Branch: Crafton
SAL Primary Order Dept: Equipment
View AR: No
View Orders: Yes
View Invoices: Yes
View Items: Yes
Enter Orders: Yes
Change Password: Yes




  #3  
Old February 27th 07, 06:45 PM posted to microsoft.public.outlook.program_vba
RitaP
external usenet poster
 
Posts: 2
Default Macro to populate contact fields no longer working

Sue, thank you, that was it. Love your books and just preordered your Outlook
2007 book at Amazon.com - you're such a great help to the user community!

Rita

"Sue Mosher [MVP-Outlook]" wrote:

I suspect that if you stepped through the code -- an essential basic troubleshooting step -- you'd find that EditorType is not olEditorText. You can probably take out the Select Case, Case, and End Select statements and have the code work fine.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"RitaP" wrote in message ...
Amateur using VBA. I copied and customized this macro a while ago and it
worked until I upgraded to Outlook 2007. What I'm doing is populating contact
fields, name, address, phone, email address from an email that contains info
in the body. The macro still creates a contact and puts it in correct contact
folder but the fields are no longer populated with info. The info I input is
being put correctly into notes section.

I haven't had time to dig in to this. Wonder if anyone can help since I
don't have new books on Outlook 2007 vba to help me. Thanks.
Rita

Macro

Sub WebContactCreateV3()

Dim objApp As Application
Dim objNS As NameSpace
Dim ContactsFolder As MAPIFolder
Dim TargetFolder As Outlook.MAPIFolder
Dim oInspector As Inspector
Dim objItem As Object
Dim objCurItem As Object
Dim strBody As String
Dim strCustnum, strSalePer, strLimits As String
Dim objContact As ContactItem
Dim strFirstName As String
Dim strLastName As String
Dim strFileAs As String
Dim strCompany As String


strCustnum = InputBox("Customer Number")
strSalePer = InputBox("Salesperson")
strLimits = InputBox("Limits")

Set objApp = Application
Set objNS = objApp.GetNamespace("MAPI")
Set oInspector = objApp.ActiveInspector
Set objItem = oInspector.CurrentItem

If oInspector Is Nothing Then
objNS.GetDefaultFolder(olFolderInbox).Items.GetFir st.Display
Set oInspector = objApp.ActiveInspector
End If

oInspector.Activate
Select Case oInspector.EditorType
Case olEditorText
BlnIsHTML = False
strBody = objItem.Body
X = InStr(1, strBody, "Name:")
Y = InStr(1, strBody, "Title:")
A = X + 6
B = Y - A
FullName = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Company:")
A = X + 7
B = Y - A
JobTitle = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Address 1:")
A = X + 9
B = Y - A
Company = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Address 2:")
A = X + 11
B = Y - A
Address1 = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "City:")
A = X + 11
B = Y - A
Address2 = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "State:")
A = X + 6
B = Y - A
City = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Zipcode:")
A = X + 7
B = Y - A
State = UCase(Mid(strBody, A, B))
X = Y
Y = InStr(1, strBody, "Phone:")
A = X + 9
B = Y - A
Zipcode = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Fax:")
A = X + 7
B = Y - A
Phone = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "Email:")
A = X + 5
B = Y - A
Fax = Mid(strBody, A, B)
X = Y
Y = InStr(1, strBody, "SAL B")
A = X + 7
B = Y - A
Cemail = Mid(strBody, A, B)
End Select
Set objItem = objApp.ActiveExplorer.Selection.Item(1)
Set objContact = objApp.CreateItem(olContactItem)
objContact.FullName = FullName
objContact.JobTitle = JobTitle
objContact.CompanyName = Company
objContact.BusinessAddressStreet = Address1 & Address2
objContact.BusinessAddressCity = City
objContact.BusinessAddressState = State
objContact.BusinessAddressPostalCode = Zipcode
objContact.BusinessTelephoneNumber = Phone
objContact.BusinessFaxNumber = Fax
objContact.Email1Address = Cemail
objContact.Body = "Cust # " & strCustnum & vbCrLf & "Salesperson: "
& strSalePer & vbCrLf & "Limits: " & strLimits & strBody
objContact.Categories = "Web Customer"
With objContact
strCompany = .CompanyName
strFirstName = .FirstName
strLastName = .LastName
strFileAs = strCompany & " (" & strLastName & ", " &
strFirstName & ")"
.FileAs = strFileAs
.Display

End With

objContact.Save

Set objCurItem = Application.ActiveInspector.CurrentItem
Set ContactsFolder =
Application.Session.GetDefaultFolder(olFolderConta cts)
Set TargetFolder = ContactsFolder.Folders("Web Customers")
Set objCurItem = objCurItem.Move(TargetFolder)

End Sub

What Subject field of email looks like: 2 blank lines then

Account: username
Password: abcdefg
Name: John Doe
Title: Operations Manager
Company: XYZ, Inc.
Address 1: 343 Smith Avenue
Address 2:
City: Anycity
State: PA
Zipcode: 12345
Phone: 555-123-4567
Fax:
Email:
SAL Branch: Crafton
SAL Primary Order Dept: Equipment
View AR: No
View Orders: Yes
View Invoices: Yes
View Items: Yes
Enter Orders: Yes
Change Password: Yes





 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
populate fields in public folder Elio Gortan Outlook - Using Forms 1 February 6th 07 01:50 AM
Why are my reminders no longer working? kuhlworship Outlook - Calandaring 2 January 25th 07 01:42 PM
Drag and drop from Lookout no longer working Matt Add-ins for Outlook 0 January 11th 07 09:59 PM
Outlook not longer working Kimmy Outlook - Installation 0 October 23rd 06 11:14 PM
How to populate fax document with contact fields HDS Outlook - Using Contacts 1 May 22nd 06 09:28 PM


All times are GMT +1. The time now is 01:22 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.