Notes control in Contact form

M

Malcolm

Hi,
I understand that all outlook forms share a message
control.
For email, it's the main body.
For contacts, it's the notes field.
I also understand that this field is bound to the Body
property of the item.

What I am having trouble with is how to refer to this
field in VBScript or VBA.
I understand how to refer to controls in general, I just
do not know what this is called programmatically.
If I look at Properties, I only see the one tab, and in
the contact form it says the name is 'Notes'.
Referring to it by this name results in an error though,
because it is not the true name.

My goal is the ability to set/unset the ReadOnly property
of the field based on the clicking of a checkbox by
particular users.
<i>
Sub EditNotes_Click()
dim MyValue, User, objPage
User = Application.GetNameSpace
("MAPI").CurrentUser
Set objPage = Item.GetInspector.ModifiedFormPages
("General")
MyValue = objPage.Controls("EditNote")
if(User = "a" Or User = "b" Or User = "c" Or User
= "d" Or User = "e") Then
<b>objPage.Controls("Notes").ReadOnly =
MyValue</b>
else
if (MyValue) then 'clicked, turn back off
objPage.Controls("EditNote") =
false
else 'not clicked, turn back on
objPage.Controls("EditNote") =
true
msgbox "Turned on"
end if
end if
End Sub
</i>
 
S

Sue Mosher [MVP-Outlook]

I don't think it's possible to programmatically lock that control, although
it can be done through its Properties dialog. An alternative approach would
be to hide the control for the users in question and show instead a plain
multi-line text box bound to the Notes/Message field:

Set objPage = Item.GetInspector.ModifiedFormPages("General")
Set Notes = objPage.Controls("Notes")
Set TextBox1 = objPage.Controls("TextBox1")
Notes.Visible = False
TextBox1.Text = Item.Body
TextBox1.Visible = True
 
M

Malcolm

That was my next step. Although this step would look
more like writing a script (I like to use Word VBA with
Outlook Reference for these one-time things) that goes
through 3,000 contacts and copies the Item.body over to
the textbox for the existing contacts. Fun! Be so much
more fun though if Outlook would dump VBscript and use
full blown VBA. That's my only quibble.

Is it possible though to refer to the control
programmatically (even if you can't lock it)? Just for
future reference in case something else comes along.

Thanks,
Malcolm
 
S

Sue Mosher [MVP-Outlook]

No, ho, no, that's not what it does at all. You would put that code in
Item_Open event handler of your custom form. In other words, the code would
run only when the user opens such an item.

The code you originally posted is correct for referring to the control if
you've renamed it EditNote.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
M

Malcolm

It's all working now, here's the final code. I changed
the code slightly to check against user names stored in
an olNoteItem in a subfolder of the contact folder. This
note item looks like:

Administrative:
John;
Jill;
Jack;

The controls I am using:
"Notes" = the Note/Message standard object
"EditNotes" = checkbox to lock/unlock it

Here is the code:

Sub EditNotes_Click()
dim MyValue, curUser, objPage, Notes, i,
boolFlag, NoteCheckBox
dim curFolder, fld, Allow_Users, User_String,
User_Position, User_Array
curUser = Application.GetNameSpace
("MAPI").CurrentUser
Set objPage = Item.GetInspector.ModifiedFormPages
("General")
MyValue = objPage.Controls("EditNotes")
Set curFolder = Item.Parent
Set fld = curFolder.Folders("CompanyNotes")
Set Allow_Users = fld.items("Administrative:")
User_String = Allow_Users.body
User_Position = instr(1, User_String, ":")
User_String = Mid(User_String, User_Position + 1,
len(User_String))
User_String = Replace(replace(User_String, Chr
(13) , ""), Chr(10), "")
User_Array = Split(Cstr(User_String), ";")
for i = 0 to Ubound(User_Array)
if (curUser = User_Array(i)) then
set Notes = objPage.Controls
("Notes")
Notes.ReadOnly = Not MyValue
boolFlag = true
Exit For
end if
next
if (Not boolFlag) then 'invalid user clicked,
make sure the checkbox is off
set NoteCheckBox = objPage.Controls
("EditNotes")
NoteCheckBox.Value = false
end if
End Sub


Thanks for the help Sue!
Malcolm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top