Custom Form, Get username?

  • Thread starter Patricia Cardoza - [MVP Outlook]
  • Start date
P

Patricia Cardoza - [MVP Outlook]

In vbscript, the code is:

Application.GetNamespace("MAPI").CurrentUser

--
Patricia Cardoza
Outlook MVP
http://blogs.officezealot.com/cardoza/

Author, Special Edition Using Microsoft Outlook 2003
Author, Absolute Beginner's Guide to OneNote 2003
Lead Author, Access 2003 VBA Programmer's Reference

***Please post all replies to the newsgroups***
 
S

Susan Wilder

I have created a custom contact form that is stored in a
public folder. The users can modify the data contained in
this folder. I want to track who has modified the data.
Being new to the VBScript, I can't get code to work, and
honestly, don't know where to start. I've spent 4 hours
searching the websites for this.

Please help me!

Susan
 
P

Patricia Cardoza - [MVP Outlook]

Well, you can do something with the Item_Open event or the Item_Write event.

Sub Item_Write()

Item.Body = Item.Body & "Changed by " &
Application.GetNamespace("MAPI").CurrentUser & chr(10) & chr(13)

End Sub

This will add Changed By Jane Doe and a carriage return to the body of the
item.
--
Patricia Cardoza
Outlook MVP
http://blogs.officezealot.com/cardoza/

Author, Special Edition Using Microsoft Outlook 2003
Author, Absolute Beginner's Guide to OneNote 2003
Lead Author, Access 2003 VBA Programmer's Reference

***Please post all replies to the newsgroups***
 
G

Guest

Being a novice, I just can't get this to work. I want
to "write" the username of the individual making the
change to the Account field of the Contact card being
modified. Can you help me with the code?

I get all confused with when to use the Dim and Set
statements.

Thanks,
Susan
 
P

Patricia Cardoza - [MVP Outlook]

Is the Account field a custom field? If so all you need is the following:

Sub Item_Write()

Item.UserProperties.Find("Account") =
Application.GetNamespace("MAPI").CurrentUser

End Sub

No need for dim or set statements here.

--
Patricia Cardoza
Outlook MVP
http://blogs.officezealot.com/cardoza/

Author, Special Edition Using Microsoft Outlook 2003
Author, Absolute Beginner's Guide to OneNote 2003
Lead Author, Access 2003 VBA Programmer's Reference

***Please post all replies to the newsgroups***
 
S

Susan Wilder

I have a customized form with a new field called User. (I
decided to change it from Account, which was a
Miscellaneous defined field). I added the code into
VBScript exactly as you defined below, changing the
word "Account" to "User". My "User" field is defined as
text and added to my form. When I open and save the form,
nothing is written to my new field. What can I be doing
wrong?

Thank you for all your time!
 
P

Patricia Cardoza - [MVP Outlook]

Did you make sure and add a field and a control? A control is the text box,
the field needs to be defined by right clicking on the control, choosing
properties, and going to the Value tab. Make sure your field is created
there.

Also, try replacing the Item_Write with Item_Open and see if the code fires
there. Did you publish the form or are you just running it? What version of
Outlook?

--
Patricia Cardoza
Outlook MVP
http://blogs.officezealot.com/cardoza/

Author, Special Edition Using Microsoft Outlook 2003
Author, Absolute Beginner's Guide to OneNote 2003
Lead Author, Access 2003 VBA Programmer's Reference

***Please post all replies to the newsgroups***
 
G

Guest

I added a new text field called Username. Both the
Display and Value properties of the control have been set
to Username. The "Property to use" field has been set
to "Value". I've tried the code as you sent and also as
seen below:

Function Item_Open()

Item.UserProperties.Find("Username") =
Application.GetNamespace("MAPI").CurrentUser

End Function

Tried both Open and Write. Is it possible that my Visual
Basic Script doesn't work? Is there a way to test that?

Again, thank you for your assistance. I feel like I'm
taking so much of your time. I guess I have to learn
somehow!
 
S

Sue Mosher [MVP-Outlook]

Did you publish the form? Code doesn't run on unpublished forms.

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

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