Delete Custom Control thru Code

  • Thread starter Thread starter Boyd
  • Start date Start date
B

Boyd

I have a custom Outlook form, which I populate all controls with data
from an Access database. I am coding the population of the form thru
Access VBA.
Is there any way to delete a control thru VBA code, or vbScript? For
example, after
populating the form, I want to delete all objects that contain null
values.
I would assume this should be fairly simple, but I'm a novice to
referencing Outlook objects.


Any help is greatly appreciated.


Thanks,
Boyd
 
Get the Controls collection for the form page and iterate it. Check for
values and delete the ones you don't want there. However, what you are doing
is strongly recommended not to do. Adding controls to a form at run-time is
guaranteed to one-off the form, which causes all sorts of problems. Better
to design the form with all controls and hide the ones with no values.
 
Thanks Ken. I agree that hiding the controls is the way to go.
Do you suggest that I code this behind the outlook form, or from within
my Access code?
Can you offer any insight as how to access the controls collection?
 
Code it in the form if possible. You can do it using code from Access but
depending on your Outlook version you risk one-offing the forms.

If the modified form page is called "P.2" then code would look something
like this (form code, using VBScript). For Access code you'd replace
Application with an Outlook.Application object and Item with a qualified
reference to the open item (possibly from ActiveInspector.CurrentItem).

Set oPage = Item.GeInspector.ModifiedFormPages("P.2")
Set oControls = oPage.Controls

From there just iterate the collection.
 
Back
Top