Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA IIF Statement in Outlook 2003 2

Status
Not open for further replies.

MichaelF81

Programmer
Sep 20, 2005
178
US
OK, I have a radio button called "reqNo" and if it is set to true, I want a field called "Required" to add "user@domain.com" to the required user field. If "reqNo" is set to false (which it is by default) I want it to not add the e-mail address.

IIf( expr , truepart , falsepart )

That is how it should work, I have set-it up and it does not. Any ideas?




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Could you show your code here?

I am sure Iif statement works OK, I am affraid your logic does not.

Do not confuse truepart, falsepart with "a radio button called "reqNo" and if it is set to true" and "reqNo is set to false"

---- Andy
 
I tried that if statement, I also tried making Required Disabeled and using the IF to enable it




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
OptionButton




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Private Sub reqNo_Change()
If reqNo = True Then
Required.value = "user@domain.com"
End If
End Sub

No good :(




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
I have two option buttons, both of them are using the same field control called "reqNo". They are individually called reqYes and reqNo




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
I tried that, but I could not get it to work. If you have suggestions on how to make it work, I would greatly appreciate it!




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Add a checkbox. We will assume that it's name is CheckBox1. I don't know what the variable "Required" is, is it another control on the userform? Maybe this code will help you understand the checkbox.

Code:
Private Sub CheckBox1_Click()
MsgBox "You just set the button to " & CheckBox1.Value
End Sub

This code will assign the checkbox state to the variable.

Code:
If CheckBox1 = True Then
   Required = "user@domain.com"
End If

You need to show us the code your using now as everything is in the details.
 
Code:
Private Sub chkbYes_Click()
MsgBox "You just set the button to " & chkbYes.Value
End Sub

Ok, I did this, clicked it, it does not work...




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Go to the VBA editor. Click on the userform module that has the checkbox. Click on the checkbox in the userform. In the Properties window, at the top, does it say "chkbYes CheckBox"?
 
I am doing this all in outlook 2003. The VB Editor is essentially notepad. It has a script menu with object browser and event browser, but I do not see my fields (only built-in fields)




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Checkboxes, IMHO, are poor choice of controls for what you want to do. Checkbox can be either checked or unchecked, and they work 'independent' of each other, which means you can have 1, 2, 3 or 15 checkboxes and all of them could be checked, unchecked or in any combinations.

Users are used to certain behavior of controls, and if you changed their behavior users will be confused.

2 option buttons (radio buttons) make sense to me.

Try:
Code:
Private Sub reqNo_Click()
    Call CheckReq
End Sub

Private Sub reqYes_Click()
    Call CheckReq
End Sub

Private Sub CheckReq()

If reqNo.Value = True Then
    Me.Caption = "No is chosen"
Else
    Me.Caption = "No is NOT chosen"
End If

End Sub

---- Andy
 
I see now, you want to have just one checkbox - this will work fine.

---- Andy
 
OK guys, I got it to work!

Code:
Function Item_Send()
If Item.UserProperties("chkbYes").value = True Then
	Item.RequiredAttendees = Item.RequiredAttendees & "; user@domain.com"		
	Item_Send = True
Else
 If Item.UserProperties("chkbYes").value = False Then
	msgbox("Danger Will Robinson.")
	Item_Send = False
 End If
End If
End Function

But, Outlook says it has active content so it will not display in the reading pane... freaking shoot,




"Adults are just obsolete children and the hell with them." - Dr. Seuss
 
Ahhh! You making a message form. One thing about the code you posted, you don't need 2 if statements because there are only 2 possible states (True or False).
Code:
Function Item_Send()
If Item.UserProperties("chkbYes").value = True Then
    Item.RequiredAttendees = Item.RequiredAttendees & "; user@domain.com"        
    Item_Send = True
Else
    msgbox("Danger Will Robinson.")
    Item_Send = False
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top