Macro Create Contact and Save

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Email Account
Exchange Server
The following code creates a new contact from my form but it will not save and the error is that the parameter value is not valid....what can we do to fix this please?

Sub OpenMyContact()
Dim oContact As outlook.contactItem
Dim oFolder As outlook.MAPIFolder
Set oFolder = Application.Session.GetDefaultFolder(olFolderContacts)
Set oContact = oFolder.Items.Add("IPM.Contact.Contact Form 1.")
oContact.Display
End Sub
 
I'm guessing the problem is not with the macro but with the form, probably with one of the custom fields, specifically one of the values in the fields. you'll need ot figure out which field is the problem - look on the All Fields page and check the user defined fields.
 
How does looking a the All Fields page and check the user defined fields show what there is a problem?
 
Look at the fields that have values. Does anything look amiss? Are other fields reading values from other fields? Are any of the fields without values set to require a value? (It's not the right error message for that though.)

You'll probably need to open the form in the forms designer and check the properties of each custom field - one option is to delete fields that have values, one at a time, and use run this form and try to save it to identify the field that has a bad parameter. As long you do don't publish the form, you won't lose the fields you delete.
 
The following code words fine, no problems and it runs another I created named "PastetoFullName" so when I create the contact, it adds to the Full Name of the contact name I copied from somewhere else....and it put's it in a folder as you see...but, is there away that it creates the contact to a folder I select, not the folder name I put in? This way, I don't have to move contacts all the time etc.

Sub NewContactFromNameSelected()
Dim oContact As outlook.contactItem
Dim oFolder As outlook.MAPIFolder
Set oFolder = Application.Session.GetDefaultFolder(olFolderContacts).Folders("New Contacts")
Set oContact = oFolder.Items.Add("IPM.Contact.Contact Form 1")
oContact.Display
Call PastetoFullName
End Sub
 
I looked at some other codes re folders and I changed the foregoing to the following, and it creates the contact using my form to the selected folder:

Sub NewContactFromNameSelected()
Dim oContact As outlook.contactItem
Dim oFolder As outlook.MAPIFolder

Set oContact = Application.ActiveExplorer.CurrentFolder.Items.Add("IPM.Contact.Contact Form 1")
oContact.Display
Call PastetoFullName

End Sub
 
There may be other areas again to do things faster, but given how you gave me a form of a code where when I run it, it adds to the fields of the contact a create, I can call that macro at the end of the code I showed, so it will add to the fields immediately when I create the contact....so also I don't know to mark the last answer as a marked answer...but I so appreciate all you have shown me over the time!!
 
I can see you are getting to be pretty good at coding. :)

There is a Best Answer link under each reply - I guess I should log in using my test account so i can see what y'all see.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Macro Create Contact and Save Using Outlook 2
S Macro to create a new contact, 2 appointments, and a task Using Outlook 1
S Outlook 365 Help me create a Macro to make some received emails into tasks? Outlook VBA and Custom Forms 1
A Outlook macro to create search folder with mail categories as criteria Outlook VBA and Custom Forms 3
Tanja Östrand Outlook 2016 - Create Macro button to add text in Subject Outlook VBA and Custom Forms 1
B Macro To Create Rule To Export From Certain Folder Email Information in one workbook multiple sheets Outlook VBA and Custom Forms 0
A Create Macro for hyperlink(email) in message body Outlook VBA and Custom Forms 9
S Macro to create notification emails Using Outlook 1
N Macro to create task Using Outlook 1
S Macro to create a new folder with subject line as the folder name Using Outlook 2
P Please Help me Create a Macro ! Using Outlook 2
M How to Create Macro in Visual Basic to add Contacts from Personal Folder Using Outlook 4
R How do I create a macro to put text in certain emails? Outlook VBA and Custom Forms 1
D Create a macro in Outlook to run a rule Outlook VBA and Custom Forms 32
N How Can I create an Outlook Macro to import calendar? Outlook VBA and Custom Forms 1
P How do I create a macro to add contacts from email messages? Outlook VBA and Custom Forms 1
J Macro to create folder in PST file Outlook VBA and Custom Forms 4
G Macro: Create New Message and Auto populate To Field Outlook VBA and Custom Forms 5
S How to create a macro to insert a signature in Outlook 2007 Outlook VBA and Custom Forms 1
X Custom icon (not from Office 365) for a macro in Outlook Outlook VBA and Custom Forms 1
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
mrrobski68 Issue with Find messages in a conversation macro Outlook VBA and Custom Forms 1
G Creating Macro to scrape emails from calendar invite body Outlook VBA and Custom Forms 6
M Use Macro to change account settings Outlook VBA and Custom Forms 0
J Macro to Reply to Emails w/ Template Outlook VBA and Custom Forms 3
C Outlook - Macro to block senders domain - Macro Fix Outlook VBA and Custom Forms 1
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
S macro error 4605 Outlook VBA and Custom Forms 0
A Macro Mail Alert Using Outlook 4
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
J Macro to send email as alias Outlook VBA and Custom Forms 0
M Outlook Macro to save as Email with a file name format : Date_Timestamp_Sender initial_Email subject Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro GoTo user defined search folder Outlook VBA and Custom Forms 6
D Outlook 2016 Creating an outlook Macro to select and approve Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
M Outlook 2019 Macro not working Outlook VBA and Custom Forms 0
Geldner Send / Receive a particular group via macro or single keypress Using Outlook 1
D Auto Remove [EXTERNAL] from subject - Issue with Macro Using Outlook 21
V Macro to count flagged messages? Using Outlook 2
sophievldn Looking for a macro that moves completed items from subfolders to other subfolder Outlook VBA and Custom Forms 7
S Outlook Macro for [Date][Subject] Using Outlook 1
E Outlook - Macro - send list of Tasks which are not finished Outlook VBA and Custom Forms 3
E Macro to block senders domain Outlook VBA and Custom Forms 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
N VBA Macro To Save Emails Outlook VBA and Custom Forms 1
N Line to move origEmail to subfolder within a reply macro Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Macro to answer a mail with attachments Outlook VBA and Custom Forms 2
A Outlook 2016 Macro to Reply, ReplyAll, or Forward(but with composing new email) Outlook VBA and Custom Forms 0

Similar threads

Back
Top