By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,663 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,663 IT Pros & Developers. It's quick & easy.

If Then Else Problem

P: 44
Hi i am trying to do the following code but it is saying i have an error "else without and if" but i do have an if below is the code
Expand|Select|Wrap|Line Numbers
  1. Private Sub StockDesc_Click()
  2.  
  3. If StockDesc = "Hard Hat" Then ExpiryDate.Visible = True
  4. If StockDesc = "Boots" Then ExpiryDate.Visible = True
  5. Else: ExpiryDate.Visible = False
  6. End If
  7. End Sub
thanks for any help
Jan 19 '12 #1

✓ answered by Rabbit

When you put the If expression Then expression code all on one line, it doesn't process any further.

You need to use this syntax instead.
Expand|Select|Wrap|Line Numbers
  1. if expression then
  2.    expression
  3. else
  4.    expression
  5. end if

Share this Question
Share on Google+
3 Replies


Rabbit
Expert Mod 10K+
P: 12,421
When you put the If expression Then expression code all on one line, it doesn't process any further.

You need to use this syntax instead.
Expand|Select|Wrap|Line Numbers
  1. if expression then
  2.    expression
  3. else
  4.    expression
  5. end if
Jan 19 '12 #2

P: 44
Thank you very much im supprised somthing like that affects it. Thanks again
Jan 19 '12 #3

NeoPa
Expert Mod 15k+
P: 31,712
If it had worked that way, then the first If line would also have required an Else. Whichever way you look at it your code was going to fail there on one of them ;-)

Anyway, let me just remind you that post #2 is ripe for selection as Best Answer and please remember to post in the correct forum another time (You must have ignored one or two warnings this time to end up in the Articles forum).
Jan 19 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.