Results 1 to 5 of 5
  1. #1
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48

    If Statement to validate Field on a Form

    Hi,

    Bit dumbstruck here, cannot understand why I get the negative result when I am validating an input field. In form1 I call form 2 with an openargs. In openargs I insert "|" & "Enquire" & "|" and in Form2 on the OPEN event, I split the Openargs by "|" and place the value in a string fielda. Then I validate if fielda = "Enquire" and if true I set Form2 control properties, i.e

    If fielda = "Enquire" Then
    allowadditions = false
    else
    allowaddition = true
    end if

    I placed a msgbox to display fielda and it contains "Enquire", however, it still tells me that fielda is not equal to "Enquire"

    Am I misunderstanding the concept of the if statement or can you only validate for Numerics and True/False values.

    Please help because I am really beginning to get frustrated and beginning to code things that does not make logical sense, i.e. in the above code, I swap my allowadditions around, i.e. if true, make false and if false, make true... very confusing if someone else had to maintain the program code at a later stage.

    Thanks
    Earl

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    You can certainly test string values. I'd disambiguate by explicitly referring to the control:

    If Me.fielda = "Enquire" Then

    where fielda is the control you want to test. If that doesn't work, have you tried setting a breakpoint to see what Access thinks is there?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48
    Hi Paul,

    Basically, on Form 2 I have an array field defined as a string that occurs 1 to 3, in each occurence I place a value, i.e. Enquire - (1), Modify - (2), Delete - (3). I then Split the me.OpenArgs by "|" into a variant field and move the 1st occurence of the variant into fielda defined as string. So the comparison is between 2 string fields, i.e. the array and fielda. Before doing the If Statement... I put a msgbox displaying both fields and they are equal in string value, yet it does not fall into the condition it should meet, see actual code below:

    If strFunction = arrFunction(1) Then
    MsgBox " Equal - " & strFunction & "/" & arrFunction(1)
    ElseIf strFunction <> arrFunction(1) Then
    MsgBox " Not Equal - " & strFunction & "/" & arrFunction(1)
    End if

    The msgbox displays "Not Equal - Enquire/Enquire". Surely this can also be considered a break to check the value of the fields in question.

    Being novice... you may need to guide me thru the breakpoint setting process and syntax.

    Thanks
    Earl

  4. #4
    ETCallHome is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2011
    Location
    Limpopo, South Africa
    Posts
    48
    Hi Paul,

    Thanks for the advise, I changed my if statement to a int = strComp(Fielda, Fieldb, Compare) and put a break point on the line of the strComp and displayed int which display -1, i.e. fielda less then fieldb, on closer inspection, I found that fielda was " Enquire " and fieldb was "Enquire". Fielda had a space before and after the work Enquire, while fieldb had no spaces.

    Does this mean the split method puts spaces before and after the variant field you insert the split data in all instances for a string field?

    Thanks ....

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,640
    The Split() function shouldn't add any spaces. What's the code that creates the string and splits it back apart?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Date Field empty if statement
    By dubsdj in forum Programming
    Replies: 4
    Last Post: 03-06-2011, 04:02 PM
  2. Validate Form Field based on Duplicate Data
    By bornfattom23 in forum Forms
    Replies: 3
    Last Post: 11-05-2010, 02:02 PM
  3. using Functions to validate a date field
    By jamin14 in forum Programming
    Replies: 1
    Last Post: 03-18-2010, 12:46 PM
  4. Replies: 2
    Last Post: 11-04-2009, 09:45 PM
  5. IIF statement to populate field
    By GriffyNJ in forum Queries
    Replies: 0
    Last Post: 10-13-2009, 10:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums