Results 1 to 11 of 11
  1. #1
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56

    Validation of one field based on another

    I have been looking around for how to do this, but have not found my particular issue resolved yet. I have one combo box in a sub form. Combo is called 'cmbProCode'. I have another box called 'txtGrpCount'. On every selection in cmbProCode I would like the txtGrpCount' to default to the number 1. I see that would be easy by using the Default item. Issue is there is one option in the cmbproCode box where this is not the case, and mistakes are often made by Dataentry here, that I why I need to work on a way to fix it. They exact issue is if they pick '514' in the 'cmbprocode' box, the number in the 'txtgrpcount' box must be 2 or more. I am needing a way for a pop up to appear if this creteria is not met before they save the record, or on the after update event of the txtgrpcount box. I am stumped as to how to make this work.

  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,652
    One way would be to test in the before update event of the form:

    http://www.baldyweb.com/BeforeUpdate.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    OK, I am new very rusty with my VB so unsure what I am doing wrong here. I tried several ways occording to the code, but can't even get a pop up to appear if I choose the 514 option.

    This is what I have at the moment:
    Code:
    If Len(Me.CMBProCode) = "514" Then
            MsgBox "You entered the group procedure code ""514"", you must enter a Group count greater than 1. Please adjust this record"
            Cancel = True
            Me.txtGrpCount.SetFocus
        End If
    I am going to continue trying to play, but I am hoping you can help.

  4. #4
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    I Got it:

    Code:
    If Me.CMBProCode = "514" And Me.txtGrpCount = "1" Then
            MsgBox "You entered the group procedure code ""514"", you must enter a Group count greater than 1. Please adjust this record"
            Cancel = True
            Me.txtGrpCount.SetFocus
       End If
    Sometimes persistance works. Sometimes it has me spinning my wheels. Glad this time it worked.
    Thanks for heading me in the right direction!

  5. #5
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    I Got it:

    If Me.CMBProCode = "514" And Me.txtGrpCount = "1" Then
    MsgBox "You entered the group procedure code ""514"", you must enter a Group count greater than 1. Please adjust this record"
    Cancel = True
    Me.txtGrpCount.SetFocus
    End If

    Sometimes persistance works. Sometimes it has me spinning my wheels. Glad this time it worked.
    Thanks for heading me in the right direction!

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help. I am surprised it works with quotes around the numbers though.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    Sorry, I accidently posted the above reply twice.

    I have been putting all my checks on the code and can't find out what I am doing wrong with the following Code. I want it to put up a message box if both of the box's are blank or 0.
    I have 2 box's. Hours and Minutes. I want to make sure records can't be entered that don't have a time associated with them. There should be some figure besides 0 in at least one of the box's. Hope that makes sense.
    I have tried the following code with <1, Is Null (although I don't want 0 only being accepted). Can you help me with this code:

    If Me.txtHours < 1 And Me.txtMinutes < 1 Then
    MsgBox "You must enter a time Greater than 1 minute. Please Adjust this record"
    Cancel = True
    Me.txtHours.SetFocus
    End If

  8. #8
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    I have kept playing and decided I really want to say If me.txthours = 0 or Is null and me.txtminutes = 0 or is null then..... Just cant work out the code. I am very rusty.

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    If (Len(Me.txthours & vbNullString) = 0 OR Me.txthours = 0) And (Len(Me.txtminutes & vbNullString) = 0 OR Me.txtminutes = 0) Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    AussieGal is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    56
    Thank you sooooo much! Worked perfectly.

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    No problemo!
    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. Form field validation question
    By usmcgrunt in forum Programming
    Replies: 1
    Last Post: 03-19-2012, 04:22 PM
  2. Data Validation of another field
    By dssrun in forum Access
    Replies: 4
    Last Post: 03-22-2011, 01:09 PM
  3. Replies: 0
    Last Post: 03-18-2011, 06:38 AM
  4. BUG! Field level date validation
    By buj in forum Forms
    Replies: 0
    Last Post: 09-16-2010, 08:23 PM
  5. Form Field Validation
    By dhav79 in forum Forms
    Replies: 3
    Last Post: 06-03-2010, 11:31 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