count boxes in form

J

JMNijsse

Hello,

I have created a new form (for an appointment) in my Outlook 2003 calendar.
In this form there are many textboxes. In that box must be put a name or
description for that appointment.
Now, I want to count automatically the number of textboxes wich are filled.
This number must be put in the 'subject' field of the calendar, so i can see
how many appointments there are.

Is there any solution for this problem?
In the dutch discussion group cames not a solution for this, so i will try
it (in my best school english) on this group.

Regards,
Johan Nijsse
The Netherlands.
 
K

Ken Slovak - [MVP - Outlook]

Each tab in the form that was modified is in the Inspector.ModifiedFormPages
collection. If one of your pages has the name of "MyPage" (as an example)
you can access it using code like this:

Dim colPages As Outlook.Pages
Dim oPage As MSForms.Page
Dim colControls As MSForms.Controls

Set colPages = item.GetInspector.ModifiedFormPages
Set oPage = colPages.Item("MyPage")
Set colControls = oPage.Controls

You can then iterate the Controls collection of that page and check the Name
property of each Control object. By default textboxes would be Textbox1,
Textbox2, etc. If you've renamed the controls use your custom names to
identify the textboxes and then you can check the Value or Text property of
each textbox to retrieve the control's contents.

See if that helps.
 
J

JMNijsse

This is very, very difficult for me.
Is it VBA code? I never worked with it, before. So its new for me.
And I have a dutch version of Outlook. So I must translate all unknown terms
and find out what it is in dutch.

But in de design-mode for Forms I can make a field or a box, and set this as
Value (for example).

Then I can with right-click on this box choose Properties. One tab names
Value. And there I can work with Formulas.

But that's no option? Is the only way VBA or very difficult code?

Regards,
JOhan
 
K

Ken Slovak - [MVP - Outlook]

That was VBA code, and the only English specific thing in it was the
imaginery name I made up for the form page. You'd just substitute your page
name.

The same code in VBScript (Outlook form code would look like this, complete
with a Function declaration:

Function CountBoxes(pageName) 'pass page name into function
Dim colPages 'As Outlook.Pages
Dim oPage 'As MSForms.Page
Dim colControls 'As MSForms.Controls
Dim oControl 'As MSForm.Control
Dim boxCount 'As Long

' use Item which is intrinsic to that open form.
Set colPages = Item.GetInspector.ModifiedFormPages
Set oPage = colPages.Item(pageName)
Set colControls = oPage.Controls

boxCount = 0

For Each oControl In colControls
' compare to see if this control has "textbox" in the control.Name
If InStr(1, oControl.Name, "textbox", 1) > 0 Then
boxCount = boxCount + 1
End If
Next

CountBoxes = boxCount

End Function
 
J

JMNijsse

Thanks, thanks.
I will try. But first I have to learn a bit of VBA or VBScript...

Greetz,
Johan
 

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