Link to home
Start Free TrialLog in
Avatar of newburgh
newburghFlag for United States of America

asked on

OL2000 Create Drop-Down Box in Custom Contact Form

I am using Outlook 2000 on a Windows 2000 computer.  I have created a custom contact form and that is working out just fine.  I have only one problem - I cannot create a drop-down box so a user can select information from a list and have the "value" of what they select show in an adjoining box.  What I would like to be able to do is create a list, most likely of telephone numbers, but there could be other applications down the road.  I would like the drop-down box to work the way it does on the default contact form.  The first page of the default form has phone number fields, and you can select items from a list and display the phone number you want.  The form also shows, via a check mark, what fields have information in them.  This aspect of the drop-down box is not important, but the rest is.

I have spent the past couple of weeks trying to figure this out by myself, but no luck.  I've searched Experts Exchange, as well as any links the experts might have suggested in various posts and looked around (Microsoft searches, etc) on my own.  I'm more confused now than I was when I started.  Can anyone out there give me step-by-step instructions on how to create a drop-down box and have the results show the value of what was selected (for example, I select "Home Phone" and the resulting diplay is 123-456-7890)?  All I've been able to accomplish is to have a drop-down box where I select "Home Phone" and my resulting display is "Home Phone", the words, not the value.  For the record, I know nothing about Visual Basic and if I can arrive at my destination without using it, or by obtaining the needed code and modifying it for my specific needs, I will be very happy.  I know enough to be able to change the key words to suit my needs, I just don't know how to write the basic code.   What I need is to understand how this works so I can re-create it to suit my particular needs.  Right now I don't even know if I should be using Text boxes, List boxes, Combo boxes or any combination of the above.  Please help!

Maureen
Avatar of David Lee
David Lee
Flag of United States of America image

Hi, newburgh.

This is doable, it's just a bit complicated in how you go about it.  I've included sample form code below that shows how to do this.  To use it you'll need to do the following.

1.  Create user properties called myChoice, myActiveChoice, and myChoiceA through myChoiceE.
2.  Add a ComboBox control to your form.  Bind it to the user property named myChoice.  Set the possible values to A;B;C;D;E.
3.  Resize the ComboBox so only its arrow is showing.
4.  Add a TextBox control to the form.  Bind it to the user property named myActiveSelection.  Place it immediately to the right of the ComboBox.
5.  Open the script editor and paste the code below into it.
6.  Save the form and then test it.

This is only to demostrate how to make this work.  Once you see how it works you can modify it as needed.  The approach is really quite simple.  When you change the combobox selection the value of myChoice changes which fires the code.  The code sees that myChoice changed, calculates which of the myChoice fields it needs to load, and loads it in myActiveSelection.  That field is bound to the textbox so the value appears there.  When you enter a value in the textbox the code is fired again (because the user property it's bound to has changed).  It sees that myActiveSelection has changed, calculates which of the myChoice fields it needs to update, and changes it's value accordingly.

I hope this makes sense.

Sub Item_CustomPropertyChange(ByVal Name)
    Dim objForm, varChoice
    Set objForm = Item.GetInspector.ModifiedFormPages("P.2")
    Select Case Name
        Case "myChoice"
            varChoice = Item.UserProperties("myChoice").Value
            varSelection = "myChoice" & varChoice
            Item.UserProperties("myActiveSelection") = Item.UserProperties(varSelection)
        Case "myActiveSelection"
            varChoice = Item.UserProperties("myChoice").Value
            varSelection = "myChoice" & varChoice
            Item.UserProperties(varSelection) = Item.UserProperties("myActiveSelection")
    End Select
    Set objForm = Nothing
End Sub
Avatar of newburgh

ASKER

Thanks for the input.  Based on what I've done with Outlook so far, it does kind of make sense, but I won't know for sure until I work with it.  It's Monday morning and I have a few things that need to get done first, but I will play with this a little later today.  I want to keep the question open until I've had time to see if this solves my problem, or at least helps me to understand how this works.  So far I've been able to create drop-down phone boxes using the pre-defined telephone lists (selector 1, selected 1, etc), but they only give Outlook's pre-defined definitions, and I can't see how they are set up to help me understand how it all works.  I want to set up my own lists, and I hope your instructions help.  I'll let you know as soon as I can get to it.

Maureen
I've had a chance to try what you suggested, and I still have a problem.  I wasn't exactly sure of what you meant by "create user properties", but I assumed you wanted me to create User-Defined fields, which I did.  I then created text boxes which I bound to myChoiceA thru myChoiceE and did everything else you suggested.  Using your instructions, I can type info into the text boxes I had created, and have that information show as I select it in the combo box.  That all works fine, and I had actually managed to do this last week by following some very basic instructions I found somewhere on the Internet.  But what I am trying to do is to have the drop-down box show different telephone numbers that might be entered somewhere else on the form I've created.  

I have created a custom contact form that uses information imported from four or five different databases in our system.  The custom form I've created has phone numbers in at least two different places.  I had limited room on the first page of the form, which is set up pretty much like Outlook's default form, so I only have a few basic numbers there.  The bulk of the phone numbers are on a second page.  Mostly I've used Outlook's field names (Home Phone, Business Phone, Mobile Phome, etc).  I would like to create a drop-down box on the first page which would list the most important (to us) phone numbers so a person does not have to go to the second page to find the number they want.  I don't want to be limited by the phone list that Outlook provides for this purpose - I want to create my own list.  Then I want the number selected from the list in the combo box to appear in the text box.  

I don't know if I'm making sense here, so I'll try to explain further.  With the instructions you gave me, I can type a phone number 123-456-7890 into the text box I've bound to myChoiceA.  I then select A from the drop-down list in the combo box, and  123-456-7890 shows in the text box to the right of the combo box.  That works perfectly.  What I would like to happen, is to set things up so the box that is now myChoiceA would default to the field Home Phone, and then select Home Phone from the drop-down list in the combo box and have 123-456-7890 show in the text box to the right of the combo box, without physically typing it because the number was input on a different page, or imported into the form previously.  I can set a text box up so it will default to Home Phone and it will display the correct phone number which had been previously entered, but I don't seem to be able to pull that "value" into a combo box/text box setup.  Does this make sense?  Is it possible to do what I am trying to do?  Also, if this is possible, can there be more than one drop-down list associated with a form?  If I get this working, I would probably like to create more than one list (one for business info, one for personal info, etc).  That might allow me to totally eliminate the second page I've had to create showing all of the phone numbers.  I want to keep this form as simple and as user-friendly as possible.  

With the instructions you've given me here, I can set up a drop-down list to show any new numbers that might be manually entered onto the form, but I can't get it to display existing numbers based on the field name.  I appreciate what you've told me so far; at least I have a base that I can use to play with and maybe eventually I'll have a better understanding of how this works.  I hope I've been able to explain my problem well enough so you might be able to help a little more.  I'm going to leave this question open for awhile.  I'll keep playing with this, but I hope you'll be able to lead me one step closer to my goal.  Thanks!

Maureen
Maureen,

> I assumed you wanted me to create User-Defined fields, which I did
Correct.  Sorry for the wording.

> I then created text boxes
That's a problem.  You only want one text box.  Think of a contact form.  A single text box shows multiple telephone number fields depending on which number you select in the pulldown.  There isn't a separate text box for each possible phone number.

> have the drop-down box show different telephone numbers that might be entered somewhere else on the form I've created
Then we don't need to add the user-defined fields since the fields we need to access are already in the form.  We'll also need to change the code to this

Sub Item_CustomPropertyChange(ByVal Name)
    Dim objForm, varChoice
    Set objForm = Item.GetInspector.ModifiedFormPages("P.2")
    If Name = "myChoice" Then
            varChoice = Item.UserProperties("myChoice").Value
            Select Case varChoice
                Choice "A"                          '<- Replace A with the name of the first choice in the list
                    varSelection = "FieldA"    '<- Replace FieldA with the name of the field that corresponds to the first choice in the list
                Choise "B"                          '<- Replace B with the name of the second choice in the list
                    varSelection = "FieldB"    '<- Replace FieldB with the name of the field that corresponds to the second choice in the list
            End Select
            Item.UserProperties("myActiveSelection") = Item.UserProperties(varSelection)
    End If
    Set objForm = Nothing
End Sub

When the user clicks the pulldown and selects an entry in the list the CustomPropertyChange event fires passing the name of the control that changed.  The code checks the name to see if it's the name of our pulldown control.  If it is, then we retrieve the control's new value.  We then use a case statement to evaluate the name to see which form field we need to display in the text box next to the pulldown.  The code as I've revised it here makes the text box associated with the pulldown read-only.  If it needs to be able to edit the field values, then we need to add a bit more.
I’ve been playing with this for quite awhile, and I’m still having problems.  I’ve tried using the code exactly as you typed it (after correcting the typo Choise-I don’t see any other places where there might be a misspelling or a punctuation error); I’ve tried modifying it and even combining it with the first script you spelled out for me, but nothing works.  I can get the drop-down box to show the names I want it to show, but the text box will not diplay the results.  

I tried to post this using an image-capture program that I have, but it wouldn't let me show the screen captures that I had, so I'll try to explain screen-by-screen what I'm seeing.  I’m sorry to be a pest, but I just don’t understand the script (if I did, I probably wouldn’t be here right now asking these questions).  I have everything else working on the form, but this one issue is driving me nuts!  One of these days I’ll have to try to learn VB, but for now I’m really at a loss.  Anyway, here’s my problem:

The script as I modified it (I only added two fields as I didn't want to do anything to "mess up" your text, I only changed what was there):

Sub Item_CustomPropertyChange(ByVal Name)
Dim objForm, varChoice
Set objForm = Item.GetInspector.ModifiedFormPages("P.2")
If Name = "myChoice" Then
varChoice = Item.UserProperties("myChoice").Value
Select Case varChoice
Choice "Home" '<- Replace A with the name of the first choice in the list
varSelection = "Home Phone" '<- Replace FieldA with the name of the field that corresponds to the first choice in
Choice "Office" '<- Replace B with the name of the second choice in the list
varSelection = "Business Phone" '<- Replace FieldB with the name of the field that corresponds to the second cho
End Select
Item.UserProperties("myActiveSelection") = Item.UserProperties(varSelection)
End If
Set objForm = Nothing
End Sub


Combo Box Properties:
 Choose Field:  myChoice
 Possible Values:  Home;Office;Cell;Home Fax;Nextel
 (nothing else changed from default)

Text Box Properties:
 Choose Field:  myActiveSelection
 (nothing else changed from default)

After typing “Run this Form” I get this error:
  Syntax error Line No. 11

When I click on OK, it takes me to the form, and after typing phone numbers in the two fields specified in the script, I can select the correct names from the drop-down list in the combo box, but nothing displays in the text box.  

At this point I really don't know what I'm doing wrong.  I tried modifying your script various ways hoping that maybe I would stumble across something that was input incorrectly (variable reversed or another typo, etc).  I looked for any place where a piece of punctuation might be missing (or added incorrectly).  To me a syntax error has to do with formatting, either because of punctuation or even spelling (going back to my DOS days).  I found nothing that seemed to be out of place and none of my changes worked.  At one point I did change something that allowed me to "Run this Form" without getting an error, but it still didn't display the values in the text box.  So, do you have any other ideas?  Thanks for what you've done so far.  I may not have a resolution to my problem yet, but I do feel like I have a better understanding of how this works.  Hopefully one day it will actually make sense.

Maureen
 


   













 


   













   












Maureen,

Ok, there are a couple of problems with the code.  There were typos on my part.  I've corrected them.  I was also still thinking that we were talking about custom properties, when now I see that you were talking about contact item properties.  I've revised the code (below) and fixed both the typos and my misunderstanding about which properties you want.  I then created a custom contact form of my own and tested this.  It worked perfectly.  I can post the form in a place where you can download it if needed.

Sub Item_CustomPropertyChange(ByVal Name)
    Dim objForm, varChoice
    Set objForm = Item.GetInspector.ModifiedFormPages("P.2")
    If Name = "myChoice" Then
        varChoice = Item.UserProperties("myChoice").Value
        Select Case varChoice
            case "Home"   '<- Replace A with the name of the first choice in the list
                varSelection = "HomeTelephoneNumber"
            Case "Office" '<- Replace B with the name of the second choice in the list
                varSelection = "BusinessTelephoneNumber"
        End Select
        Item.UserProperties("myActiveSelection") = Item.ItemProperties.Item(varSelection)
    End If
    Set objForm = Nothing
End Sub
I tried this new script but still nothing.  I even scrapped the form I was practicing on and made a new copy of my custom form to start from scratch with this.  I can run the form with no errors using the new script, but when I select an item from the combo box, the text box remain blank.  It does not display the value of what I've selected.  

Could there be some sort of problem with one of the boxes, either in Properties or Advanced Properties?  When I set each up, I left the default settings except for binding the boxes to myChoice for the combo box and myActiveSelection for the text box, per your instructions.  I then set the the possible values in the combo box to Home Phone and Business Phone. Other than that I made no changes to either box.  I also tried your script "as is", but then I tried changing "Home" and "HomeTelephoneNumber" to Home Phone, which is the actual field name and "Office" and BusinessTelephoneNumber" to Business Phone (again, the true field name) and made sure the possible values in the combo box were input as these two names.  I would like the combo box to show Home and Office, but I thought maybe if everything read exactly the way Outlook's default fields read that it might work.  I was wrong.

One other thing, the one line of the script reads ("P.2").  Does this refer to the page the combo box is located on?  If so, I am using page 6 of the form for practice.  I have been trying the script with both P.2 and P.6 with each change I've tried to make, but neither works.  I'm just curious about this as every piece of sample code I've seen since I've been researching this has shown P.2.  I'm just not sure what that stands for.

So, as it stands I'm about ready to scrap this whole idea and learn to live without drop-down boxes.  I know this has to be something really stupid on my part that I've set up incorrectly, but I can't figure out what that might be.  You mention setting up a form somewhere where I could see it.  Would I be able to look at the form the way you do when in the design mode?  That's really what I need to see in order to relate to what I'm trying to do.  If I can see a form that works, I know I could figure out what I'm doing wrong.  Anyway, I'll await your reply.  Thanks again, and sorry for being such a problem.

Maureen
ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Well, I downloaded your form and tried using it.  I get the same results I was getting setting up my own form (the value of the selected item does not show in the text box).  If this form works for you, but does not work for me, then there HAS to be another issue kicking in here that is affecting the outcome.  In looking quickly, it appears that I was setting things up exactly the way your form is set up.  I will take some time today and go over everything with a fine-tooth comb to make sure I did everything exactly as you did.  If I did, then the process is not the problem.  For that reason I am going to go ahead and award the points.  I want to thank you for all of your help - you've really gone way out of your way on this one and I appreciate it.  I'll study your settings and see if I can't at least start to understand the VB code, even if I can't get the form to work.  

One last thing, if this is an Outlook issue rather than a problem with the code or setup of the combo & text boxes, is there another section in Experts Exchange that you know of who might be able to help me?  I'm going to play with this some to see if I can figure out why this isn't working, but I may need help.  SOMETHING is preventing the results from showing in that text box.  What I'll probably do is email the zip file to myself at home and try it on my home computer.  If it works there, then I'll know it has something to do with the settings on my computer here at work.

Anyway, thanks again - you've been very patient and you've been a tremendous help.  

Maureen  
Hi, Maureen.

It's been awhile since I used Outlook 2000, I built the form I uploaded using Outlook 2003, so maybe it just can't do this.  Just to be sure, you filled in the home or business phone number on the first page of the contact form, then went to page 2, clicked the pulldown, selected home or office (I don't remember exactly how they were worded), and the text box next to the pulldown remained blank?

No, I don't think there's another topic area here on EE that would be able to help with this problem.  I don't mind continuing to work with you on this if you decide you want to keep at it.  

Thanks for the grade and the kind words.
I did enter the info on the first page, then tried to see it by selecting the field from the drop-down box, but the adjoining text box remained blank.  It could very well have something to do with the difference in versions.  I emailed the form to myself at home and tried it there also, wehre I use XP.  I got the same results as here.  

Before posing this question I had already created the custom contact form that we will probably use here in the office.  The drop-down box was a "would have been nice to have" issue for that form, and it's something we felt we would want to be able to do for future applications.  For now I am going to keep playing with what you've supplied to me.  I don't understand the "commands" in VB so I can't write it myself, but I can look at the code and sort of figure out what it's trying to do.  I can change little things around, such as the field names.  You kept using "HomeTelephoneNumber" and "BusinessTelephoneNumber", but I know my Outlook sees those codes as "Home Phone" and Business Phone", so even though I tried your code "as is", I also changed those field names in the code and tried it again.  I will keep trying to tweak what you've written and maybe I'll stumble across something that works.  I will keep the original code that you wrote as a starting point and just try different things.  

I appreciate your offer of help, but at this point I feel that we could work on this forever and it may never work.  If you happen to think of anything that you feel might help, I would appreciate hearing from you.  But for now I think I'm just going to play with this whenever I have  a little time and hope I can eventually figure it out.  Thanks again for everything!

Maureen