textbox visible or not with click of a checkbox

G

Guest

I am trying to set it so that I have a userform that when a checkbox is
clicked a textbox field will start. I have tried the set (obj) style, i have
tried the item.userproperities and i cannot get it to work. currently this is
what i have


Sub Item_CustomPropertyChange(ByVal Name)
Select Case Name
case "OPTD"
If Item.UserProperties("OPTD") = True Then 'CHECKBOX
Item.UserProperties("REASON").Visible = True 'TEXTBOX1
Item.UserProperties("CONFIRMATION").Visible = True 'TEXTBOX2
elseIf Item.UserProperties("OPTD") = False Then
Item.UserProperties("REASON").Visible = False
Item.UserProperties("CONFIRMATION").Visible = False

end if
end select
End Sub

I keep getting this error:
Object doesnt support this property or method: "Visible"
Line No:5

and also this error message:
Object doesnt support this property or method:
Item.UserProperties(...).Visible
Line No:8

Any help here please
 
S

Sue Mosher [MVP-Outlook]

You mean a custom Outlook form, not a VBA userform, right?

You're apparently a little mixed about about the difference between controls and properties (also called "fields"). Properties are just data values. They're not visible or read-only or blue or bold. They're just text or numbers or dates etc. Controls are the user interface elements that can be visible or read-only or blue or bold. Two can be linked through the concept of a "bound" control, in which the value entered into the control automatically becomes the value of the property bound to the control.

The other important thing to know about bound and unbound controls is how that state affects what event fires when the user changes a value in a control. If the control is not bound to a property, the control will fire a Click event (for those controls that support it -- text boxes don't). If it is bound to a property, no Click event fires. Instead, you work with the two events related to properties -- PropertyChange and CustomPropertyChange.

So, your code below apparently has that last point down fine -- you're using the CustomPropertyChange event just fine.

The problem is that you're trying to change the Visible property of an object (UserProperty) that has no such property. Instead, you need to be changing the value of the Visible property of the *control* that is bound to the REASON property. That involves getting the page that the control resides on, then getting the control. There's a code snippet and more detailed explanation at http://www.outlookcode.com/d/propsyntax.htm#unbound

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

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

Guest

Thanks I actually got it figured out last night using this:
Sub Item_CustomPropertyChange(ByVal Name)
if item.userproperties.find("OPTD") = true then
item.getinspector.modifiedformpages("Message").controls("TextBox1").visible
= true
item.getinspector.modifiedformpages("Message").controls("TextBox2").visible
= true
elseif item.userproperties.find("OPTD") = False then
item.getinspector.modifiedformpages("Message").controls("TextBox1").visible
= false
item.getinspector.modifiedformpages("Message").controls("TextBox2").visible
= false
end if

if item.userproperties.find("OPTD1") = true then
item.getinspector.modifiedformpages("Message").controls("TextBox3").visible
= true
item.getinspector.modifiedformpages("Message").controls("TextBox4").visible
= true
elseif item.userproperties.find("OPTD1") = False then
item.getinspector.modifiedformpages("Message").controls("TextBox3").visible
= false
item.getinspector.modifiedformpages("Message").controls("TextBox4").visible
= false
end if

if item.userproperties.find("OPTD2") = true then
item.getinspector.modifiedformpages("Message").controls("TextBox5").visible
= true
item.getinspector.modifiedformpages("Message").controls("TextBox6").visible
= true
elseif item.userproperties.find("OPTD2") = False then
item.getinspector.modifiedformpages("Message").controls("TextBox5").visible
= false
item.getinspector.modifiedformpages("Message").controls("TextBox6").visible
= false
end if
End Sub
 
S

Sue Mosher [MVP-Outlook]

That's it! You can even simplify it quite a bit:

Set myPage = item.getinspector.modifiedformpages("Message")
myPage.Controls("TextBox1").Visible = Item.UserProperties("OPTD")
myPage.Controls("TextBox2").Visible = Item.UserProperties("OPTD")
myPage.Controls("TextBox3").Visible = Item.UserProperties("OPTD1")
myPage.Controls("TextBox4").Visible = Item.UserProperties("OPTD1")
myPage.Controls("TextBox5").Visible = Item.UserProperties("OPTD2")
myPage.Controls("TextBox6").Visible = Item.UserProperties("OPTD2")

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