Results 1 to 11 of 11
  1. #1
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68

    Validate with code Yes or No

    I need to validate yes or no with code. I thought this would be easy. Access does not like "Not in"


    If (Me.TxtActualBenchmark) Not in "Yes" or (Me.TxtActualBenchmark) Not in "No" And txtBenchmark.value = "Free lunch for all students Yes/No" Then
    MsgBox "Please answer Yes or No"
    Exit Sub
    End If

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    not YES
    or
    not NO

    dont use IN

  3. #3
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68
    Ok Thank you I will try it

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Is the Field that is Bound to TxtActualBenchmark defined as Text or Boolean Datatype?

    Linq ;0)>

  5. #5
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68
    It is defined as text. I still can't get it to work

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The conditional statement doesn't really make sense.

    If TxtActualBenchmark must be either "Yes" or "No" then the Or operator doesn't work.

    Maybe:

    If (Me.TxtActualBenchmark) <> "Yes" And (Me.TxtActualBenchmark) <> "No" And Me.txtBenchmark = "Free lunch for all students Yes/No" Then

    Or:

    If IsNull(Me.TxtActualBenchmark) AND Me.txtBenchmark = "Free lunch for all students Yes/No" Then

    Maybe TxtActualBenchmark should be a combobox with only two items listed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68
    Yes it has been quite a challenge. I am building it for a department head in another department. I will try that and see if it works. Thank you

  8. #8
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68
    Maybe there is another way to say it.

  9. #9
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68
    I'm going to look at it again in the morning it's 7:00 over here

  10. #10
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68

    Here is my form hope it attached

    ScorecardsGina.zip This is the form

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    1. Main form is bound to Geans (actually an SQL statement pulling from Geans but could just be the table), however no controls are bound to fields so why is there a RecordSource?

    2. Geans does not have a primary key field. It appears data is being duplicated into Scorecards table. There is no relationship between Geans and any other table. What is this table for?

    3. None of the tables have a primary key defined, yet there is a link between Scorecards and BusinessDepartment on common Groups field - which is the primary and which is the foreign key field?

    4. Why have code behind main form to create records into Scorecards table when the subform is bound to Scorecards and data can be directly input through subform?

    5. This could be one form - set the form for Continuous View, move unbound controls and buttons into form header and Scorecards fields stay in detail section, arrange controls in detail to appear as datasheet. Maybe you should explore the Split form object.

    6. One way to force data entry into bound controls is to set fields as Required in the table then Access will nag the user to enter data before the record can be saved. No code required.

    7. The RowSource for Fiscal Year combobox will have to be edited every year. The RowSource can be constructed by code or by reference to a table of years.

    Have you done a thorough analysis of the database specifications? Have you identified all data entities and relationships? Should get data structure established before trying to build GUI and code. Perhaps this site will be of help http://www.rogersaccesslibrary.com/
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Validate textboxes before more VBA
    By cjriebe in forum Programming
    Replies: 3
    Last Post: 06-25-2014, 09:07 AM
  2. Validate a field
    By tweety in forum Forms
    Replies: 19
    Last Post: 03-29-2013, 04:06 PM
  3. validate based on another value
    By subnet11 in forum Programming
    Replies: 3
    Last Post: 06-11-2012, 12:12 AM
  4. Validate Subfrom Data
    By mcktigger in forum Forms
    Replies: 2
    Last Post: 09-08-2011, 09:50 AM
  5. How to validate data using MS Access
    By maniii in forum Import/Export Data
    Replies: 2
    Last Post: 09-01-2011, 07:29 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