Results 1 to 11 of 11
  1. #1
    amandag
    Guest

    If statement (97)

    Please can someone help. I want to write the following code
    If (Len(Me.cboFirstDate) = 0) Or (Len(Me.cboRecentDate) = 0) Then strMessage "Enter a value for compare dates"
    so that the message is the same if there is nothing selected in either of the combo boxes. It is the OR part of the statement that I am having problems with. How do I get the statement to make a decision based on one OR the other condition.

    Thanks in advance for any help.

  2. #2
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: If statement (97)

    I think that you want to use AND instead of OR.

    HTH --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

  3. #3
    amandag
    Guest

    Re: If statement (97)

    thanks Sammy

    but I definately want to say if one OR the other is true - not if thy aer both true.

  4. #4
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: If statement (97)

    Your question confuses me ... do you mean you want something like:

    If (Len(Me.cboFirstDate) = 0) Then
    variable_x = strMessage "Enter a value for First Date: "
    ElseIf Or (Len(Me.cboRecentDate) = 0)
    variable_y = strMessage "Enter a value for Recent Date: "
    End If
    'continue processing ...
    -John ... I float in liquid gardens
    UTC -7ąDS

  5. #5
    amandag
    Guest

    Re: If statement (97)

    Thanks John

    But that is not quite what I want. I want to have the same message if one of 2 possible conditions are true i.e. if one of my combo boxes is empty. I don't want to have to repeat what I want the message to be twice when the message is the same. Hope that makes more sense

    Amanda

  6. #6
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: If statement (97)

    The syntax you have used should be ok for an OR selection, but the strMessage would give problems, as it is not as far as I know a VBA statement. Would the following help : ?<pre>If Len(Me.cboFirstDate) = 0 Or Len(Me.cboRecentDate) = 0 Then MsgBox "Enter a value for compare dates"</pre>


    Andrew C

  7. #7
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: If statement (97)

    Hi,
    You didn't actually say what was wrong with your code - are you getting an error? There's nothing wrong with it other than the fact that you're missing an equals sign between strMessage and "Enter a value for compare dates". (I'm assuming you then have a MsgBox strMessage statement)
    Regards,
    Rory

    Microsoft MVP - Excel

  8. #8
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: If statement (97)

    Doh! I blew right by that!
    -John ... I float in liquid gardens
    UTC -7ąDS

  9. #9
    amandag
    Guest

    Re: If statement (97)

    You are quite right it. A simple error of forgetting to put in an equal sign and look what can happen.

    Many thanks.
    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  10. #10
    Uranium Lounger
    Join Date
    Dec 2000
    Location
    Salt Lake City, Utah, USA
    Posts
    9,508
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Re: If statement (97)

    ... an = sign and either MsgBox or more likely InputBox. Although I'm a good proofreader of standard written English, I am constantly making mistakes like this in my own coding work. Andrew C gets the credit for this one.
    -John ... I float in liquid gardens
    UTC -7ąDS

  11. #11
    Silver Lounger
    Join Date
    Mar 2001
    Location
    Springfield, Ohio, USA
    Posts
    2,136
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: If statement (97)

    > want to say if one OR the other is true - not if thy are both true

    Sorry, in this case you wanrt to use XOR, but you will have to turn the logic around:
    <pre>If (Len(Me.cboFirstDate) > 0) XOR (Len(Me.cboRecentDate) > 0) Then
    strMessage = "OK"
    Else
    strMessage "Enter a value for compare dates"
    End If</pre>

    What the above is saying is:
    If there is text in the first combo box or text in the second combo box but not text in both, then message is OK, otherwise message is error. If this is not what you want, just write back more information. HTRH (Hope this really helps!) --Sam
    <font face="Comic Sans MS">Sam Barrett, CACI </font face=comic>
    <small>And the things that you have heard... commit these to faithful men who will be able to teach others also. 2 Timothy 2:2</small>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •