?
Solved

Pass VBA UserForm Selected  Listbox Item Value To ThisOutLookSession Module

Posted on 2014-03-24
5
Medium Priority
?
4,829 Views
Last Modified: 2014-03-28
In Outlook 2007 I have created a VBA UserForm (UserForm1) on which I have placed a single-column Listbox control (Listbox1).  I populate the Listbox conrol with the FullName of each Contact that is present in the Contacts folder.  This works without problem.

When I select one of the Contacts in the Listbox located on the VBA UserForm (Listbox1), I need to pass the value for the selected Listbox item to the VBA code running in the ThisOutlookSession module.  Is this even possible?  If so, what does the code look like?

Thanks,

Bill Vallance
0
Comment
Question by:bvallanc
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
englanddg earned 1200 total points
ID: 39952005
In your sub in your module, you can use UserForm1.ListBox1.Value to call the value selected in the ListBox.

Here's a sample of what I mean.

Open a blank spreadsheet.  Create a module (We'll call it Module1).  Add this code.

Sub test()
    MsgBox (UserForm1.ListBox1.Value)
End Sub

Open in new window


Create a userform.  We'll call it UserForm1.  To that add a Listbox (called ListBox1) and a Command Button (CommandButton1)

Then, in the FORM code, add this code.

Private Sub CommandButton1_Click()
    Call test
End Sub

Private Sub UserForm_Initialize()
    ListBox1.AddItem ("test1")
    ListBox1.AddItem ("test2")
End Sub

Open in new window


As you can see, I'm using the command button on click event to call the test sub in the module.  Then calling the selected value of the listbox and displaying it in a message box in the test sub.

Hope this helps!
0
 

Author Comment

by:bvallanc
ID: 39952213
This works when the code is created in a Module.  It doesn't seem to work if the code is created in ThisOutLookSession (I've created all of my code (so far) in ThisOutLookSession).  Is this correct?
0
 
LVL 3

Expert Comment

by:englanddg
ID: 39952232
Do you mind posting your code?

As far as I know, a public module is the best solution.  At least...it's the solution that will work!
0
 

Author Comment

by:bvallanc
ID: 39963126
Thanks, englanddg, for your answer.  I was hoping that someone would specifically answer my question about how to communicate between a standard Module and the ThisOutLookSession module.  Since I have taken your advice and placed my code in a standard Module I think it's fair to award 50% of the points for your time and effort.

Thanks for your help!

Bill Vallance
0
 

Author Comment

by:bvallanc
ID: 39963129
Englanddg, you got all 400 points because I don't have the time to screw around with allocating points.  Thanks so much for your help with this problem.
Regards,

Bill Vallance
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question