PC Review


Reply
Thread Tools Rate Thread

A beginners Elseif question

 
 
Cerberus
Guest
Posts: n/a
 
      22nd Jul 2008
I have a user form I created and it has a few option buttons on it to specify
what type of suspension the customer wants. I have it set up so there are
two options for spring and two main options for air. The problem I am having
is if you select spring first and then decide you want air, the information
you enter form there on will effect spring and not air. I put in an Elseif
statement on one of the spring options but I am not sure if I need to put one
on the other also or if I simply did not write it correctly. Please take a
look at what I did and guide me in the right direction

Private Sub OptionSpring_Click()
Range("B27").Formula = "=L175"
Range("J199").Value = "SPRING"
Range("J203").Value = "NO LIFT"
End Sub

Private Sub OptionSprinL_Click()
If OptionSpring = False Then
ElseIf OptionSprinL = False Then
Range("B27").Value = 0
End If
Range("B27").Formula = "=L175-K195"
Range("J199").Value = "SPRING"
Range("J203").Value = "LIFT"
End Sub

 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      22nd Jul 2008
You don't need an elseif . Look at the two examples below

Private Sub OptionSprinL_Click()
If OptionSpring = False Then
'code if required
Else
Range("B27").Value = 0
End If
Range("B27").Formula = "=L175-K195"
Range("J199").Value = "SPRING"
Range("J203").Value = "LIFT"
End Sub

Private Sub OptionSprinL_Click()
If OptionSpring = True Then
Range("B27").Value = 0
End If
Range("B27").Formula = "=L175-K195"
Range("J199").Value = "SPRING"
Range("J203").Value = "LIFT"
End Sub


"Cerberus" wrote:

> I have a user form I created and it has a few option buttons on it to specify
> what type of suspension the customer wants. I have it set up so there are
> two options for spring and two main options for air. The problem I am having
> is if you select spring first and then decide you want air, the information
> you enter form there on will effect spring and not air. I put in an Elseif
> statement on one of the spring options but I am not sure if I need to put one
> on the other also or if I simply did not write it correctly. Please take a
> look at what I did and guide me in the right direction
>
> Private Sub OptionSpring_Click()
> Range("B27").Formula = "=L175"
> Range("J199").Value = "SPRING"
> Range("J203").Value = "NO LIFT"
> End Sub
>
> Private Sub OptionSprinL_Click()
> If OptionSpring = False Then
> ElseIf OptionSprinL = False Then
> Range("B27").Value = 0
> End If
> Range("B27").Formula = "=L175-K195"
> Range("J199").Value = "SPRING"
> Range("J203").Value = "LIFT"
> End Sub
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      22nd Jul 2008
I am going to try and explain this without confusing you. The statement can
be true when the value equals false:

This statement: If OptionSpring = False Then

can be true or false. If it is not true, then the next line will not execute.

This line: ElseIf OptionSprinL = False Then

will execute only if the statement on the first line is true. You do not
need to use ElseIf when you use the If...Then without a condition on the fist
line. You could just use a second If. Both statements must be true for B27
to equal zero. That is, both options must equal false.

expl: If OptionSpring = False Then
If OptionSprinL = False Then
Range("B27").Value = 0
End If
End If

I hope this helps you to organize your controls. I did not fully understand
your objective so I won't offer any code for that.



"Cerberus" wrote:

> I have a user form I created and it has a few option buttons on it to specify
> what type of suspension the customer wants. I have it set up so there are
> two options for spring and two main options for air. The problem I am having
> is if you select spring first and then decide you want air, the information
> you enter form there on will effect spring and not air. I put in an Elseif
> statement on one of the spring options but I am not sure if I need to put one
> on the other also or if I simply did not write it correctly. Please take a
> look at what I did and guide me in the right direction
>
> Private Sub OptionSpring_Click()
> Range("B27").Formula = "=L175"
> Range("J199").Value = "SPRING"
> Range("J203").Value = "NO LIFT"
> End Sub
>
> Private Sub OptionSprinL_Click()
> If OptionSpring = False Then
> ElseIf OptionSprinL = False Then
> Range("B27").Value = 0
> End If
> Range("B27").Formula = "=L175-K195"
> Range("J199").Value = "SPRING"
> Range("J203").Value = "LIFT"
> End Sub
>

 
Reply With Quote
 
Cerberus
Guest
Posts: n/a
 
      22nd Jul 2008
Thanks for spelling it out for me. It make more sense now. Thanks for both
of your help on this.

"JLGWhiz" wrote:

> I am going to try and explain this without confusing you. The statement can
> be true when the value equals false:
>
> This statement: If OptionSpring = False Then
>
> can be true or false. If it is not true, then the next line will not execute.
>
> This line: ElseIf OptionSprinL = False Then
>
> will execute only if the statement on the first line is true. You do not
> need to use ElseIf when you use the If...Then without a condition on the fist
> line. You could just use a second If. Both statements must be true for B27
> to equal zero. That is, both options must equal false.
>
> expl: If OptionSpring = False Then
> If OptionSprinL = False Then
> Range("B27").Value = 0
> End If
> End If
>
> I hope this helps you to organize your controls. I did not fully understand
> your objective so I won't offer any code for that.
>
>
>
> "Cerberus" wrote:
>
> > I have a user form I created and it has a few option buttons on it to specify
> > what type of suspension the customer wants. I have it set up so there are
> > two options for spring and two main options for air. The problem I am having
> > is if you select spring first and then decide you want air, the information
> > you enter form there on will effect spring and not air. I put in an Elseif
> > statement on one of the spring options but I am not sure if I need to put one
> > on the other also or if I simply did not write it correctly. Please take a
> > look at what I did and guide me in the right direction
> >
> > Private Sub OptionSpring_Click()
> > Range("B27").Formula = "=L175"
> > Range("J199").Value = "SPRING"
> > Range("J203").Value = "NO LIFT"
> > End Sub
> >
> > Private Sub OptionSprinL_Click()
> > If OptionSpring = False Then
> > ElseIf OptionSprinL = False Then
> > Range("B27").Value = 0
> > End If
> > Range("B27").Formula = "=L175-K195"
> > Range("J199").Value = "SPRING"
> > Range("J203").Value = "LIFT"
> > End Sub
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ElseIf question TomK76 Microsoft Excel Programming 2 2nd Apr 2009 08:22 PM
If....Elseif.....Else....Endif simple question, please help =?Utf-8?B?QWdlbnQgRGFnbmFtaXQ=?= Microsoft Access VBA Modules 12 23rd Nov 2006 03:47 AM
If-Then-ElseIf Simple Question Brandon Johnson Microsoft Access Forms 0 28th Sep 2006 03:02 PM
If-Then-ElseIf Simple Question Brandon Johnson Microsoft Access Forms 0 28th Sep 2006 03:01 PM
If-Then-ElseIf Simple Question Brandon Johnson Microsoft Access Forms 0 28th Sep 2006 02:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:07 AM.