Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2013
    Posts
    23

    Unanswered: If statement help

    I need help writing the following as an if statement

    If textbox1 = textbox2
    Then Textbox3 can = 1 or above

    else if textbox1 does not = textbox2
    Then Textbox3 cannot = 1 or above

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If textbox1 = textbox2
    means if the control textbox1 = textbox2 NOT the actual text or value
    If textbox1.text <> textbox2.text and textbox3.value >=1 then
    msgbox ("textbox 3 is:" & textbox3.value & " but textbox1 & textbox2 are not equal",vbexclamation,"Oh Shaggy")
    endif
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    The syntax

    If textbox1.text <> textbox2.text

    is not going to work and will, I believe, pop and error; the Text Property of a Control is only available when that Control has Focus, and obviously two Controls cannot have Focus at the same time.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    I would use textbox1.Value and textbox2.Value. Be also aware that if one of the values being compared to is Null, any comparison operator will not yield the result you"re probably expecting but Null instead (see here under). Either test for Null first or Use the Nz() function to convert a possible Null to some value that can enter in a comparison operation. Keep in mind that If A = B Then... actually means If (A = B) = True Then..., which can never be the case when Null is present in the comparison.

    Code:
    Dim A As Variant
    Dim B As Variant
    ' Compare Null with some value.
    A = 5
    B = Null
    Debug.Print A = B ' --> Yields Null
    Debug.Print A <> B ' --> Yields Null
    ' Compare Null with Null.
    A = Null
    B = Null
    Debug.Print A = B ' --> Yields Null
    Debug.Print A <> B ' --> Yields Null
    Have a nice day!

Posting Permissions

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