Results 1 to 10 of 10
  1. #1
    Banker_Sam is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    3

    Validation Rule / Mandatory Field

    From a form, I have a field labelled AMOUNT and a field labelled DATE. Is it possible to make DATE mandatory if data is entered into the AMOUNT field?

  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,521
    I can't think of a way with a validation rule, though I don't use them a lot. You could use the form's before update event:

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

  3. #3
    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
    There's a number of approaches to checking whether or not a Control is populated, and Paul's is fine, and using it, something like this:

    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
      If Len(Me.Amount) <> 0 Then
       If Len(Me.DateField & vbNullString) = 0 Then
        MsgBox "You need to fill out the Date Field!"
        Cancel = True
        Me.DateField.SetFocus
       End If
     End If
    End Sub

    Note that if your Field/Control is actually Date you need to change that to something else as Date is a Reserved Word. I used DateField in the example.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    There's your fish.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    deepakg27 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2017
    Posts
    160
    Thanks for the code will be useful for me.

    Regards
    Deepak Gupta

  6. #6
    Banker_Sam is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    3
    Thanks for that, I applied the code to fields labelled CLAIM AMOUNT and DATE CLAIM SENT. If an amount is entered into CLAIM AMOUNT but DATE CLAIM SENT is blank then the error message appears.

    Now for Stage 2...

    I tried applying the came principle to fields labelled PAID AMOUNT and DATE CLAIM RECEIVED but it impacts another filed DIFFERENCE (CLAIM AMOUNT minus PAID AMOUNT). It results in a name error. Do i need to apply the code to DIFFERENCE instead?

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    What is your code and what exactly is the error?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    Banker_Sam is offline Novice
    Windows XP Access 2013 32bit
    Join Date
    Nov 2017
    Posts
    3
    What I’m trying to do is
    If LMIClaimAmount is greater than 0 then LMI_Sent_Date must be greater than 0. If not, an error message is to appear.
    If LMIClaimAmountPaid is greater than 0 then LMI_Received_Date must be greater than 0. If not, an error message is to appear.
    The Difference is LMIClaimAmountPaid minus LMI Claim Amount
    The LMI Delay is LMI_Received_Date minus LMI_Sent_Date

    Below is the code I am using, but running these concurrently is impacting the fields Difference and LMI Delay, resulting in an error.


    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Len(Me.LMIClaimAmount) <> 0 Then
    If Len(Me.LMI_Sent_Date & vbNullString) = 0 Then
    MsgBox "Please complete the Date Claim Sent field located on the LMI Details tab!"
    Cancel = True
    Me.LMI_Sent_Date.SetFocus
    End If
    End If
    End Sub

    Private Sub Form_BeforeUpdate(Cancel As Integer)
    If Len(Me.LMIClaimAmountPaid) <> 0 Then
    If Len(Me.LMI_Received_Date & vbNullString) = 0 Then
    MsgBox "Please complete the Date Paid field located on the LMI Details tab!"
    Cancel = True
    Me.LMI_Received_Date.SetFocus
    End If
    End If
    End Sub


    Any assistance is greatly appreciated.

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can't have more than one sub for the same event, if that's not a typo. You can have more than one test in a single sub:

    Code:
    Private Sub...
      If Something Then
         Do Something
      End If
    
      If SomethingElse Then
         Do SomethingElse 
      End If
    End Sub
    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. Replies: 2
    Last Post: 06-09-2016, 04:18 AM
  2. Validation Rule in Multi Value Field
    By lima in forum Access
    Replies: 3
    Last Post: 10-14-2014, 12:14 PM
  3. Replies: 3
    Last Post: 05-02-2012, 04:05 AM
  4. Validation rule for a month field
    By Alliana Gray in forum Access
    Replies: 7
    Last Post: 08-11-2011, 12:41 PM
  5. Validation rule for a text field
    By wasim_sono in forum Forms
    Replies: 4
    Last Post: 03-14-2006, 11:39 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