If-Then Syntax in form?

C

Cwhitmore

I'm trying to check for a condition in a text box on a form when the "done"
button is hit. It's telling me the second line has a syntax error. Can
someone help with this?
I'm using Exchange 2003 with Outlook 2003.

Sub DoneButton_Click 'Runs when DoneButton is clicked.
If TextBox2.Text <> ""
OptionButton2.Value = Yes
Endif
Item.Close(0) 'Close the form. (0) means don't ask for confirmation.
End Sub
 
B

Bill Le May

Cwhitmore said:
I'm trying to check for a condition in a text box on a form when the
"done"
button is hit. It's telling me the second line has a syntax error. Can
someone help with this?
I'm using Exchange 2003 with Outlook 2003.
Try:

Sub DoneButton_Click 'Runs when DoneButton is clicked.

If TextBox2.Text <> "" Then
OptionButton2.Value = Yes
End If
Item.Close(0) 'Close the form. (0) means don't ask for confirmation.
End Sub
 
C

Cwhitmore

Bill,
Nothing happens when I hit the button so I took out the IF Then statement.
The "Compose" form closes properly with just the click and close statement,
but nothing happens in the "Read" form when I hit the button.
I tried giving the button in the Read form a different name, but it looks
like both forms use the same Code page?
Carlton.
 
B

Bill Le May

Cwhitmore said:
Bill,
Nothing happens when I hit the button so I took out the IF Then statement.
The "Compose" form closes properly with just the click and close
statement,
but nothing happens in the "Read" form when I hit the button.
I tried giving the button in the Read form a different name, but it looks
like both forms use the same Code page?
Carlton.

I always use one form for both Read and Compose, so I won't have much
insight there. I always use the debugger to trace execution. Place a Stop
statement in the Sub(s) you want to test and step through them. When the
code hits a Stop it will automatically ask if you want to debug. Then you
can step line by line, examine/change values. It's also a good learning tool
if you're new to Outlook forms.
 
C

Cwhitmore

Bill,
If I hit save and then close the form it works. What is the code to save
before closing a form?
Does Microsoft have a good site for coding in forms?
thanks,
Carlton.
 
S

Sue Mosher [MVP-Outlook]

If the form doesn't run code after you have sent or saved an item using the
form, you probably have done something to "one-off" the form. Outlook 2003,
Outlook 2002, Outlook 2000 SP2 and Outlook 2000 or 98 with the Email
Security Update will not run code on one-off forms; see
http://www.outlookcode.com/d/secforms.htm for more information on this
issue.

To ensure that a form does not one-off:

-- Make sure the "Send form definition with item" box on the (Properties)
tab of the form is *not* checked. [1]

-- For in-house corporate use with Exchange Server, publish the form to the
Organization Forms library or a public folder's forms library, as
appropriate for your application.

-- For collaboration via the Internet, publish your form to your Personal
Forms library. Save it as an .oft file and send it to other people who need
to use it with instructions to publish it with the same form name that you
used.

Many other things can cause one-off forms. If the above steps don't work on
a new item created with your form, see
http://www.slipstick.com/dev/formpub.htm#oneoff for other possible causes.

[1] Whenever you publish a message form, Outlook will suggest that you may
want to check the "Send form definition with item" box to ensure that the
recipient will have the form, especially if you're sending to someone via
the Internet. In the current Outlook security environment, this suggestion
is obsolete. Ignore it unless your form has no code behind it.


--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
B

Bill Le May

Cwhitmore said:
Bill,
If I hit save and then close the form it works. What is the code to save
before closing a form?

Depending on your intent you could invoke Item.Send, Item.Save or Item.Post.
The last would be appropriate if your custom form is based on a Post item.
Does Microsoft have a good site for coding in forms?

outlookcode.com is a good place, and I highly recommend Sue Mosher's book
"Microsoft Outlook Programming".
 

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