[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Outlook Form VB

I am starting my first custom Outlook form design. It contains several ComboBoxes that i will need to fill from MySql tables. I think i have all of the code required to access the DB properly from VB but i can seem to get the VB to to execute when i run the form. Can someone please point me in the right direction?

  • 6
  • 5
1 Solution
Make sure you put the code in the 'open' event of the form.

I've given an edited example of some code from one of my working forms.
THis works fine for drop downs.

It used to get screwed up for list boxes if you added items after the form loaded (the items got double spaced). Not sure if MS ever fixed that.
Function Item_open()
End Function

Sub LoadStaffNames
	'* 'Tasks' is the name of the tab on which your form controls are placed - e.g 'General, P.1 etc 
	Set oControls=Item.GetInspector.ModifiedFormPages("Tasks").Controls
	set myDropDown1 = oControls("cmbNames1")
	For I = 1 to numEntries
		myItemtoAdd = '* some code to get your data value '*

	set oControls = nothing
End Sub

Open in new window

ChuckRushAuthor Commented:
Good Morning   thanks for getting back to me. I have similar code in the Item_Open routine. Perhaps i need to know where an explanation of the Object types and available events can be found. I have ordered several books but if you know of a link that would help.

First of all if i am in design mode and i choose to 'Run this form' the code never fires. If i select macros and choose the code it does execute. I am sure i am missing some thing basic here. I have been an access developer for a long time and i guess that model is not the same. When i step into the line that starts OControls =  i get an error looking for an object and i think i need to define OControls as a type.

Any other pointers?
Hi ChuckRush,

OK - the best book is by Sue Mosher - Microsoft Outlook Programming 2007
She used to run a web site where all these kinds of issues were discussed:
Lost of info and samples there.

Microsoft supplied their own 2 part introduction.
Prt 1 is here:
Its would be well worth reading both parts.

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

If you put a.....

    msgbox "Hello"

....statement as the first and only line of your Item_open() function - does that fire?
If not its a permissions type thing, if it does its a bug in your code!

With custom forms, you need to publish them to the folder you want to use them in(although it should work to test them by just using the 'run this form' option from developer mode).

What type of form is it?

ChuckRushAuthor Commented:
Ok Thanks -- I did order the first book. the Msgbox does not display. I used a Journal entry to start with and added a couple of Comboboxes to the 2nd page. If i go from design mode to 'Run this Form' it displays my form but does not display the code. I published it and it also did not fire the code.
ChuckRushAuthor Commented:
OK I found part of my problem. I was putting code into the Visual Basic editor instead of the script editor. When i put a msgbox there it does display. I am still trying to figure out how to call a VB routine from the script editor. It looks as if script does not have a debug mode -- again what am i missing here.
Script is as basic an editor as you will find.

I debug forms using msg boxes - displaying values of key information.

It might help to have an example working form to start from.

I have a sales opportunity management form based on a task form in a pst file you can download.
It has been on my web site for several years, but it might point you on the right direction.


Save the pst file to your file system, and then open from outlook by selecting open outlook data file and navigate to the location you saved the pst file.

I don't think it has any combos loading items, but the code from my first post shows you how to do that. You just need to get the correct name of the tab which the controls are on .
You need to put all your form code in the form. VB routines included (they will need to be vbscript routines)
ChuckRushAuthor Commented:
Thanks i am sure this will help but the pst does nothave the referenced folder
The folder is there because I tested it before I posted the comment.

Its is a task folder, so the navigation pane will need to be showing tasks, or folder list for you to see it.
ChuckRushAuthor Commented:
Thanks -- this have given me the jump start i needed.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now