automating data input on a contact form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am needing a macro that I can asign to a button on the toolbar of my
contacts with they are opened for editting. I'd like the button to put
information in the field <Job Title>. The information I'd like to have put
in is:
"some text" + Today's Date in this order.
I'd like this to be inserted in the beginning of the field's data, if any,
rather than replacing the existing data.
Can someone point me in the right direction? Many thanks, Charlie
 
Try this macro:

Sub InsertAutoTitleIntoContact()
Dim objContact As Outlook.ContactItem

If Application.ActiveInspector Is Nothing Then Exit Sub
If Application.ActiveInspector.CurrentItem.Class <> olContact Then Exit
Sub

Set objContact = Application.ActiveInspector.CurrentItem

objContact.JobTitle = "some text - " & Date & " " & objContact.JobTitle

Set objContact = Nothing
End Sub
 
Hi Eric,
I couldn't get this to work. I opened a contact, and then chose
Tools/Macros/ and made a new macro like you said, and saved it. But when I
trie to run it, it said "The macros in this project are disabled." So I went
to Tools/Macros/Security and set the security level to low. But it still
gives me this messege. I went ahead and choose "customize the menu bar" and
put the macro on my menu of my contact form, but clicking on it doesn't seem
to do anything. I figured it'd give me the same message, but it doesn't do
that either. ??? I am running Outlook 2000 w/SP-3 if that helps you tell
what my problem might be...
Thanks,
ck

....also, will the date show up in this format (1/30/05) or will I need to
add something to tell it which format?
 
First, you have to reboot Outlook for the macro security settings changes to
take effect.

Did you create the macro in your ThisOutlookSession module? If so, make
sure that you have mapped the macro to a custom button properly: in the
toolbar customize dialog, click the Commands tab, select Macros from the
Categories list, and scroll the right list until you see
ThisOutlookSession.InsertAutoTitleIntoContact, then drag that to an open
Contact form.

To make sure that the macro is run when you click your custom button, put
your cursor on the 'Sub InsertAutoTitleIntoContact()' line in the VB Editor,
and press F9 to set a breakpoint. If your macro security settings are set
properly, and your custom button is mapped to the macro properly, the editor
should open when you click the button and it will stop the processing on that
line.

To change the format that the Date function generates, use the Format
function (see Help for a description of the function).
 
Hi Eric,
Thanks! That did it. I didn't have the macro in ThisOutlookSession.
Will this macro be saved and transfered along with the custom form when I
save the form to use on a different PC?

One more thing that would make this little macro perfect is this:
Say for example that <Job Title> contained the following text:

In 1/1/05 (sometext)


What I would like to happen when I run this macro would be that it would
change it to:

Out & <today's date> plus all the text that is to the right of and including
the bracket (.
I know this is simple to do with something like InStr, or Len or something,
but I can't quite get it in my mind hhow to check the position of the
bracket...
thanks,
ck
 
The macro is stored in the VbaProject.OTM file. See:

OL2000: Managing and Distributing Outlook VBA Projects:
http://support.microsoft.com/?kbid=229911

Another option is to convert the code to VBScript and include it in the code
behind your custom form. However, you'd have to write more code to retrieve
your custom button programmatically so that you can bind to it's Click event
(but the code might wind up being fired a different way altogether, depending
on your solution).

Here's a solution to your string problem:

Dim strX As String, strNew As String, intX As Integer

strX = "In 1/1/05 (sometext)"
intX = InStr(strX, "(")
strX = "Out " & Date & " " & Mid(strX, intX, Len(strX) - intX + 1)
 
Hi, I got this macro up and working great. There are a couple more things
I'd like it to do, though.
1. To move the focus (cursor) to the <job title> field, immediately
following the first bracket "(".
2. To copy this information about the contact to the clipboard:
Full Name + Paragraph return mark + Mailing Address

Many Thanks, Charlie (CK)
 
1. You can only set references to controls on forms by using VBScript in the
code behind the form, not with VBA. See the SetFocus method.

2. I think you can use the Win32API to work with the clipboard, otherwise
see the SafeInspector object from Redemption (http://www.dimastry.com).
 
....I'm not fimaliar with the Win32API. Does this mean there's not a simple
line of code I can add to this macro to make it copy the name & address to
the clipboard?
Thanks,
ck
 
Back
Top