Delete Custom Control thru Code

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
 
K

Ken Slovak - [MVP - Outlook]

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.
 
B

Boyd

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?
 
K

Ken Slovak - [MVP - Outlook]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top