Results 1 to 14 of 14
  1. #1
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111

    Conditional Data Entry Requirement

    I have a form whose datasource is a 3 field table. There is one field that is required and is restricted to 3 specific values. This is set up to be the 1st field the user enters data in. I would like the second field to be required ONLY when there is a particular value in field 1. How would I do this in the form?

  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,641
    I would use the before update event of the form:

    http://www.baldyweb.com/BeforeUpdate.htm

    but amending the test to fit your needs.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    Thanks for that reference but the stuff on that page is meaningless to me. I don't know VB so I have no idea what I would change in that to make it work on my form.

    Basically, I'm trying to enact

    If Field1Entry="XYZ" then Field2Entry is required.

  4. #4
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    Is there anyone that give me an idea of how to do this when you don't know VB?

  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,641
    The test would look like:

    If Me.Field1Entry="XYZ" And Len(Me.Field2Entry & vbNullString) = 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    Ok. Trying it now. I need to take some introductory VB for Applications or something. I hate not understanding what I'm doing.

  7. #7
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    This is the code as it actually appears in my database.

    Private Sub BoxNumber_BeforeUpdate(Cancel As Integer)
    If Me.Location = "WAREHOUSE" And Len(Me.Field2Entry & vbNullString) = 0 Then
    MsgBox "You need to fill out Box Number."
    Cancel = True
    Me.BoxNumber.SetFocus
    End If

    However, even if I put WAREHOUSE in the Location field I can pass right through the BoxNumber field without anything stopping me. What did I do incorrectly?

  8. #8
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    The before update event for a control does not happen if you just pass through it using Tab.

    As Paul suggested, you should put your checks (i.e. validation) in the Before Update event of the form, where you can cancel the update (Cancel = True) if any of the validations fail. Cancelling the update does not delete any of the data you have entered into the current record - it just prevents the data from being saved until it is valid.

  9. #9
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    So does that mean I need to change the first line of that code? Should it be just

    Private Sub BeforeUpdate(Cancel As Integer)

  10. #10
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Private Sub Form_BeforeUpdate(Cancel As Integer)
    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.

  11. #11
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    Whoo hoo! It seems to be working! Thanks, all!

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    Glad you got it sorted out.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    JeffGeorge is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    111
    Does the "Me" in the code refer to the local object, such as Form in this case?

  14. #14
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Yes, it is shorthand reference to the object the code is behind.
    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. Replies: 5
    Last Post: 03-09-2014, 07:16 PM
  2. Replies: 6
    Last Post: 09-27-2012, 08:27 AM
  3. Conditional entry into form- Intresting
    By shanky365 in forum Forms
    Replies: 7
    Last Post: 07-28-2011, 06:55 AM
  4. Conditional data entry access: intresting
    By shanky365 in forum Access
    Replies: 1
    Last Post: 07-20-2011, 02:51 AM
  5. How do I undo the requirement to login every mdb
    By garymkrieg in forum Security
    Replies: 3
    Last Post: 07-11-2011, 03:53 PM

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