One more...let's focus!

R

Robert

I've got a custom property to validate two fields. I want to validate as the
user exits the field (rather than using the field validation done at form
close). If the value is outside the script logic, I clear it.

Problem is, I can't seem to find a way to put the focus back on the control
(text box) that created the validation error.

Where is setfocus or .focus or "go to this control" in VB Script? I guess I
really should have done all this in VBA but my boss wanted an
"organizational" form on our exchange server.

TIAs,
Robert
 
S

Sue Mosher [MVP-Outlook]

SetFocus is a method of each control. You need to show the correct page, get the control, then use SetFocus:

Set insp = Item.GetInspector
Set page = insp.ModifiedFormPages("your custom page")
Set ctrl = page.Controls("name of your control")
insp.SetCurrentFormPage "your custom page"
ctrl.SetFocus

Unfortunately, it doesn't work 100% of the time.

Another tactic would be to turn the control's text red by setting its ForeColor property. See http://www.outlookcode.com/d/propsyntax.htm#unbound for more information on working with controls

That page also covers the CustomPropertyChange event that you'd need to use to respond to the user entering data for a particular property.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
R

Robert

Sue,

Thanks for your help, you've always been quick to respond.

Unfortunately, this technique didn't work, in fact I had tried something
very similar. The setfocus is within a Select Case statement. I don't know if
that would have anything to do with it not working.

The color change option isn't appropriate as it doesn't "force" the user to
change the field value. What I'm doing is this: using the custom property, if
the value of the field is greater than 2400 (military time) then display
warning, clear the value and (here's the doesn't work part) shift focus back
to the field in question. Since the custom property fires after exiting the
field by the time the other code executes focus has moved to the next field.

Here's a snippet:

case "txtFromTime","txtUntilTime"
Set insp = Item.GetInspector
Set page = insp.ModifiedFormPages("Message")
If strPropName = "txtFromTime" Then
Set strField = page.txtFromTime
Else
set strField = page.txtUntilTime
End If
set strHours = page.intHours
intValue = int(strField.value)
strMessage ="You have entered an invalid time!" & vbCrLF & "Please
re-enter a time using Military Format!"
IF intValue > 2400 Then
msgbox strMessage, vbCritical,"A T T E N T I O N"
strField.Value = ""
strHours.Value = Null
strField.SetFocus
 
S

Sue Mosher [MVP-Outlook]

That's why I generally do validation in the Item_Send or Item_Write event handler. You can certainly blank the control and put up a message, though.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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