Check/convert to emailaddresses

Status
Not open for further replies.

VincentM

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
I have a custom form, where CC and BCC are filled from a custom field with addresses which are selected through checkboxes, e.g. selecting box1 and box3 will result in "box1@somewhere.com; box3@somewhere.com".

This is working perfectely, however upon sending I receive the message "This operation failed".
I think the problem is that it is hard coded to the text field compiling the different boxes in the string needed, but it seems Outlook is not able to then "convert" the text to 'emailaddresses'. I tested futher and linked the CC info to the TO field, I found out that there is an action first to "checks/converts" the text to emailaddresses or names underlined. When I delete the original CC field, sending is no problem.

Is there any way to do this action on the CC field as well?

I hope you can post some code, which I can use and work further on. Code is for me easier to understand than general descriptions telling what I should do.
 
Hi Diane,

I have two pages in my custom form:
- Message: this is the form
- ADMIN: this are all the 'supporting field'

On Message I have checkboxes, which are linked to text boxes on ADMIN, called chkbxo1val, chkbxo2val etc.
When the checkbox is checked, the corresponding textbox will show the email address + ;
This is set by inital value: IIf([chkbxo1]=-1,"name@domain.com;","")

Also on ADMIN, I have the final result of all checkboxes in a text box called chkbxototal.
This is set by inital value: [chkbxo1val] & [chkbxo2val] & [chkbxo3val] & [chkbxo4val] & [chkbxo5val]

This is linked to CC on the Message page, using initial value [chkbxototal].

For testing purpose I added the following to my vba:

With objItem
.To = objItem.CC
End With

Resulting that the value of CC is copied in TO, but in this field it IS converted to useable email adresses (underlined), which is not happening with the text in CC.



-----------------

Just for reference the full vba text:

Sub StampDate()
Dim objOL As Outlook.Application
Dim objItem As Object
On Error Resume Next
Set objOL = Application
Set objItem = objOL.ActiveInspector.CurrentItem


If Not objItem Is Nothing Then
If objItem.BodyFormat = olFormatHTML Then
Set objNS = objOL.Session


' Check message
Prompt$ = "bla bla bla"
If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check before Sending") = vbNo Then
Exit Sub
End If


' Set Sent from account
With objItem
.SentOnBehalfOfName = name@domain.com
.To = objItem.CC
End With


' Set English text
strStyle = "'font-family:" & Chr(34) & "Calibri" & Chr(34) & ";color:black'"
strTextEng = "<p>" & "<span style=" & strStyle & ">" & _
"text text <b>" & objItem.subject & "</b> text text"" & "</span></p>" & "<br><br>" & "<p>"

' Set Hyperlink
strLink = "<p>" & "<span style=" & strStyle & ">" & "<b><a href=" & Chr(34) & "mailto:" & objItem.CC & "?cc=" & objItem.BCC & "&Subject=text" & objItem.subject & "&Body= text text text & "</span></p></a></b>"
' Set Chinese text
strTextCh = "<p>" & "<span style=" & strStyle & ">" & _
ChrW(-27068) & ChrW(20214) & "</span></p>"


' Set body
objItem.HTMLBody = Replace(objItem.HTMLBody, "<head>", "<head>" & strTextEng & strLink & strTextCh, , , vbTextCompare)


' Closing
End If
End If

Set objOL = Nothing
Set objNS = Nothing
Set objItem = Nothing


End Sub
 
Try resolving the recipients -
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients
For Each objOutlookRecip In objItem.Recipients
objOutlookRecip.Resolve
Next
 
Hi Diane, I copied your suggestion between 'Set body and 'Closing.
Unfortunately this doesn't solve the issue.
Any other suggestion?
 
Try moving the resolve outside of the code that creates the message - after one or both if's. And if that fails... you said
With objItem
.To = objItem.CC
End With

allowed them to resolve - so try moving from bcc to cc and see if it works. :)

also, rather than setting the cc field to the value of the combination field, assign the combo field to a string and set the string as the CC.

strCC = UserProperties("chkbxototal")
objitem.cc = strCC


If you post the template or form file, I'll test it and see if i can figure out why it's not working. It's definitely something with resolving the addresses as addresses (which it should do on send automatically).
 
Dear Diane, it is killing me... the UserProperties you have said to me already before, but I cannot call the user defined fields for some reason, that is why (also in the hyperlink) I now use the objitem.cc and objitem.bcc

Please find attached the form and the vba text.
Really hope you could make it work!
 

Attachments

  • working vba.txt
    5 KB · Views: 674
  • order mail for checking Diane.zip
    26.7 KB · Views: 416
Well, the problem is due to the calculated value - it updates every time you click the cc or bcc field.

This:
Dim objOutlookRecip As Recipient
Dim Recipients As Recipients
For Each objOutlookRecip In objItem.Recipients
MsgBox objOutlookRecip
objOutlookRecip.Resolve
Next

Works, but the resolved names are replaced by the calculated value. (adding the message box slowed it down so i could see what was happening)
 
Ok... so this works - the resolve code should be at the end, before the closing, or at least after the cc and bcc are set. Technically,. you might be able to get away with not using the resolve code - outlook should resolve it on send.

Remove the calculated value from the cc and bcc field and use this in the macro.

Code:
With objItem
  .SentOnBehalfOfName = "accounts@slipstick.com"
  .CC = .UserProperties("chkbxctotal").Value
  .BCC = .UserProperties("chkbxototal").Value
End With


  Dim objOutlookRecip As Recipient
  Dim Recipients As Recipients
  For Each objOutlookRecip In objItem.Recipients
  ' MsgBox objOutlookRecip
  objOutlookRecip.Resolve
  Next

What might be better is using code in the form to set the cc/bcc fields... well, maybe not, since you need vba to set the body.
 
Well, after crashing outlook 10 times, I realized i forgot to add 'value' to the code. Now it works. :)
on the form: a button named btnOK . After checking the boxes, click Done! and the addresses are added to the cc and bcc fields. The advantage of this method is that the sender can see the addresses after adding them and you could use the vba macro to send the message after building the body.

In the script editor:
Code:
Sub btnOk_Click()
Item.cc = Item.userproperties("chkbxctotal").value
Item.bcc = Item.userproperties("chkbxototal").value

end sub

button.png
 
Dear Diane, first happy new year!
Thank you so much for helping me out on this.
It is working like a charm (don't use the extra button though)...

All I needed apperantly from the beginning was the .value part in combination with item.userproperties.
I don't understand where this went wrong and that I didn't pick it up from any of the numerous other examples I have use to build this macro. Anyway very happy with your help!

Will keep on using you forum for inspiration and (parts of) solutions!
 
Well, considering how long it took me to realize it was the missing .value... you shouldn't be too hard on yourself. :) It's too easy to overlook the simple, minor things.

and (parts of) solutions!

Hehe... I started a Lazy Programmer series of articles last year, so named because the macros are created from other macros.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
P turn off the default "all day" check box in new calendar items. How? Using Outlook 1
L Help: set flag for sent mail to check if received an answer Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to check Cursor & Focus position Outlook VBA and Custom Forms 8
CWM550 Saving Data: Don't check certain folders Using Outlook 2
Victor.Ayala Automated way to check the option "Show this folder as an email Address Book" Outlook VBA and Custom Forms 2
D Spell check Outlook VBA and Custom Forms 3
L Spell-check dictionary confusion Using Outlook 0
S How to export urls from email to excel and check the status of the url ? Using Outlook 5
N Private check box in table view Using Outlook 0
S Outlook to check for specific text Outlook VBA and Custom Forms 3
C Custom Outlook Form - Populate Information from Radio Button / Check Box Using Outlook 0
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
A Check for words in subject header before sending email Outlook VBA and Custom Forms 4
R Using "check for duplicates" for existing contacts Using Outlook 2
P Suppress dialog box on email check error? Using Outlook 5
Potty Ash MS Outlook 2010 custom form - validation or formula to request user to check a checkbox Outlook VBA and Custom Forms 16
I Check if sent email has been replied Outlook VBA and Custom Forms 1
K adding more rules to 'different domains check' macro Outlook VBA and Custom Forms 2
R Macro to check file name with outlook address book Outlook VBA and Custom Forms 0
Diane Poremsky Check Contacts before moving them to Hotmail Contacts folder Using Outlook 0
Diane Poremsky Check for missing attachments before sending a message Using Outlook 1
R Outlook 2010 Modify Style "Do not check spelling or grammar" not saving Outlook VBA and Custom Forms 0
K check for sender, follow to my personal adress and delete the sent folder. Outlook VBA and Custom Forms 1
J Send and Receive Button - only check default account? Using Outlook 1
A Check for attachment code not working Outlook VBA and Custom Forms 1
Diane Poremsky Check Message Size Before Sending Using Outlook 0
B Check for different domains macro to be triggered by specific domains only Outlook VBA and Custom Forms 2
JorgeDario how to check a MailItem has a digital signature (SMIME) with vba? Outlook VBA and Custom Forms 1
O Unable to check name. Using Outlook 3
R Outlook Custom form check if there an attachment Outlook VBA and Custom Forms 2
L Trying to check for the absence of mail. Outlook VBA and Custom Forms 1
S Check if two organisition is added then i have to give managers passward creteria to send mail Using Outlook 1
Peter H Williams check for new email automaticlly Using Outlook 12
C Unusual Signature & Spell Check Query Using Outlook 1
M Calendar navigation displays previous field records.check calendar is shared.. Using Outlook 3
A Can Rule Check Category Contact is assigned? Using Outlook 1
T Outlook 2007 forms: Check boxes and free text boxes not retaining data Using Outlook 1
L check if send message appears in SendItems forder before moving Using Outlook 0
C Create a rule to only check new content in email - disregard original content Using Outlook 3
M Outlook Rules check for new line character Using Outlook 1
G Outlook rule check for messages not received Outlook VBA and Custom Forms 2
E Outlook could not create the work file. Check the temp environment variable Using Outlook 8
B Custom real time, time format check Outlook VBA and Custom Forms 1
B BCM shuts down everytime I try to import/export or check for error BCM (Business Contact Manager) 10
D Check whether mail item is proper for sending or not Outlook VBA and Custom Forms 5
P Check for the distribution list existence Outlook VBA and Custom Forms 1
H out to check whether outlook configured or not Outlook VBA and Custom Forms 1
M Check Profile info Outlook VBA and Custom Forms 1
L Check sent email and reply if have specific words Outlook VBA and Custom Forms 2
Z Check if email was sent Outlook VBA and Custom Forms 1

Similar threads

Back
Top