Results 1 to 6 of 6
  1. #1
    Abdulaym is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2023
    Posts
    33

    Fields

    Hi, I have two fields, I.e. FieldA and FieldB and in which Field B contain a value in it while FieldA is empty.



    If the value enter in Field A is greater than the value in FieldB then FieldA should not accept the value.

    Thanks for your usual assistance

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Use a form for your data entry.
    Use the Form's Before update event, which can be cancelled, to validate the data being entered.
    EDITED
    Use code something like:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)    If Not Me.FieldA < Me.FieldB Then
            Cancel = True
            MsgBox "FieldA must be smaller than FieldB"
        End If
    End Sub
    Post back if you need more help.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Abdulaym is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2023
    Posts
    33
    Good day sir, thanks for your response

    There is a pop-up message that FieldA must be smaller than FieldB, but the value subtract from FieldB by getting a negative value. If the value is bigger the value should not enter FieldA. Thanks I really Appreciate your effort sir

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Abdulaym View Post
    ..... but the value subtract from FieldB by getting a negative value. If the value is bigger the value should not enter FieldA......
    I don't understand what that means.
    As a guess, try this:
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)    If Not Me.FieldA < Me.FieldB Then
            Me.FieldA = Null
            Cancel = True
            MsgBox "FieldA must be smaller than FieldB"
        End If
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,942
    Quote Originally Posted by Abdulaym View Post
    Good day sir, thanks for your response

    There is a pop-up message that FieldA must be smaller than FieldB, but the value subtract from FieldB by getting a negative value. If the value is bigger the value should not enter FieldA. Thanks I really Appreciate your effort sir
    You never said anything about subtraction?
    Put the code in the BeforeUpdate of control A then.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    Abdulaym is offline Advanced Beginner
    Windows 10 Access 2010 64bit
    Join Date
    Jul 2023
    Posts
    33
    The first code work sir, I miss something which I just corrected. Thank you very much sir

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

Similar Threads

  1. Replies: 7
    Last Post: 10-27-2022, 07:32 PM
  2. Replies: 3
    Last Post: 12-02-2017, 02:04 PM
  3. Replies: 3
    Last Post: 04-24-2016, 07:24 AM
  4. Replies: 8
    Last Post: 08-02-2012, 10:50 AM
  5. Replies: 12
    Last Post: 05-07-2012, 12:41 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